[PATCH v2] New mechanism for declaring const-covariant string functions.

Paul Eggert eggert@cs.ucla.edu
Tue Nov 22 06:07:00 GMT 2016


Zack Weinberg wrote:
> This patch absorbs the entire mess into a pair of macros,
> __CONST_COV_PROTO and __CONST_COV_BUILTIN, which are far less
> error-prone to use, and which make the public header files much nicer
> to read, too.

That is a impressive use of the C preprocessor.

Question: if I get the types wrong with a C or C++ program, what do the 
resulting diagnostics look like? For this invalid program:

   #include <string.h>
   char *
   foo (int *x, int p)
   {
     return strchr (x, p);
   }

I currently get a diagnostic that ends like this:

   /usr/include/string.h:231:14: note: expected ‘const char *’ but argument is 
of type ‘int *’
    extern char *strchr (const char *__s, int __c)
                 ^

and this is is reasonably easy to follow in isolation. Would it be as easy to 
follow with the proposed patch? (Similarly for C++.)



More information about the Libc-alpha mailing list