[Adding back bug-gnulib in CC] Marc Nieper-Wißkirchen wrote: > > Marc Nieper-Wißkirchen wrote: > > > For example, do we want to encourage the writing of > > > sophisticated macros like the TRACE macros in chapter 16 of (the IMHO > > > opinionated) book Modern C ([1]). > > > > This TRACE macro is an interesting academic example. I say "academic", > > because who wants a trace statement that outputs only numbers, no string > > arguments? And once you allow string arguments, you notice that you need > > a varargs function, not a macro. > > Unless you want to use _Generic of C11, you probably need a varargs function.
Do you have an idea which compilers support _Generic and which don't? > > > [1] https://gforge.inria.fr/frs/download.php/latestfile/5298/ModernC.pdf > > > > Will I learn something by reading this book, or will it spoil me? :-) > > There's possibly something to learn but I don't think that one will be > spoiled. :) A number of things look interesting but also quite > Idiosyncratic to me. Due to these things, I wouldn't suggest the book > to a beginner who wants to learn C, though. > > For example, the author suggests to use a prototype like > > void foo (X x [static 1]); > > to denote that the argument "x" is a non-null pointer to a value of > type "X". While this seems to be the intent of "[static 1]" in the C > standard, it doesn't generalize well when "X" does not denote a > complete type. In that case, one has to resort to > > void foo (X *x); > > as pointers to incomplete types are fine. Also, if that's the intent of the syntax, it has been overlooked by the GCC developers. See: ============================ decl.c ============================ #include <stddef.h> extern void foo1 (double x [static 1]); extern void foo2 (double x []) __attribute__ ((__nonnull__(1))); int bar () { foo1 (NULL); foo2 (NULL); return 1; } ================================================================= $ gcc -Wall -S decl.c decl.c: In function 'bar': decl.c:9:3: warning: null argument where non-null required (argument 1) [-Wnonnull] 9 | foo2 (NULL); | ^~~~ (This is with gcc 10.1.0.) clang, OTOH, produces warnings for both foo1 and foo2. But I won't spend time to report a GCC bug on this, because - as you said - without the ability to declare a pointer to an incomplete type or a 'void *' as non-null, this language feature is worthless. Bruno