Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #27057 > unrolled thread
| Started by | "Aaron W. Hsu" <arcfide@sacrideo.us> |
|---|---|
| First post | 2012-10-05 19:25 -0400 |
| Last post | 2012-10-06 11:03 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.c
Thoughts on the _Generic feature? "Aaron W. Hsu" <arcfide@sacrideo.us> - 2012-10-05 19:25 -0400
Re: Thoughts on the _Generic feature? Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-06 11:03 +0200
| From | "Aaron W. Hsu" <arcfide@sacrideo.us> |
|---|---|
| Date | 2012-10-05 19:25 -0400 |
| Subject | Thoughts on the _Generic feature? |
| Message-ID | <op.wlqbc42b0p3ku8@localhost> |
With C11 comes the _Generic feature to enable a form of generic programming. That's pretty nice, actually, from my standpoint, but I wonder if others who do more programming in C than I have thoughts on it? I use C mostly as a means to implement other languages, so I have some fondness for the ability to do this sort of generic programming. -- Aaron W. Hsu | arcfide@sacrideo.us | http://www.sacrideo.us Programming is just another word for the Lost Art of Thinking.
[toc] | [next] | [standalone]
| From | Jens Gustedt <jens.gustedt@loria.fr> |
|---|---|
| Date | 2012-10-06 11:03 +0200 |
| Message-ID | <506FF3D9.3060505@loria.fr> |
| In reply to | #27057 |
Am 06.10.2012 01:25, schrieb Aaron W. Hsu: > With C11 comes the _Generic feature to enable a form of generic > programming. That's pretty nice, actually, from my standpoint, but I > wonder if others who do more programming in C than I have thoughts on > it? I use C mostly as a means to implement other languages, so I have > some fondness for the ability to do this sort of generic programming. I started using it on different levels and I find it quite usefull. But it also has several drawbacks. I use it in P99 to build up other parts of the C11 emulation, in particular the atomic macro/function interfaces. It works quite well, I think, but the complexity that the _Generic feature imposes in that case is nothing that you would want to do in every day's coding: the fact that all branches of a _Generic expression must be valid C under all circumstances is a real head ache. I also use it in some other project to do some sorts of function overloading. Here it is a real help to reduce the interface complexity for users of the project: the project has two struct types that have similar functionality and so _Generic can be used to unify the interface. I also use it to distinguish pointer and array arguments to the functions. The implementation of these interfaces is still tough, but less sophisticated than for P99. That said, there is also a serious flaw that is uncovered by type generic expression, the underspecification of qualified versions of rvalues. Before C11 the type of an rvalue has not been observable, so the qualifiers of that type where not important. With _Generic it becoms observable, and has quite nasty consequences. If you want to write type generic code you'd sometimes have to enumerate over all 8 (ordinary types) or 16 (pointer types) combinations of qualifiers for each base type that you are interested in. If you write e.g an interface that captures all integral types you'd have 12 x 8 = 96 cases to consider. Not only that such a thing is a nightmare to maintain, for the actual compilers it also is a performance burden during compilation. If have written ideas about that problem up on p99.gforge.inria.fr/defects-and-improvements/DR-qualified-rvalues.html But to come back to _Generic: it is a usefull feature, but certainly nothing that you want to propose to beginners. But for library implementors it can be a nice tool to wrap up interfaces. Jens
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web