#define const before including system headers?

Mark Schreiber mark7@alumni.cmu.edu
Thu Nov 11 09:11:00 GMT 2004

The following code snippit:

#define const
#include <stdlib.h>
int foo(const void *a, const void *b)
  return 0;
int main(void)
  qsort(NULL, 0, 0, foo);
  return 0;

produces the following warning on gcc 3.3.3:

$ gcc bar.c
bar.c: In function `main':
bar.c:11: warning: passing arg 4 of `qsort' from incompatible pointer type

A little bit odd, since I would have expected the definition of const
to nothingness to remove the consts from the system headers as well as
the local source file, preventing warnings from coming up.  Sure
enough, passing this snippit through cpp results in qsort() prototypes
that contain no const type modifier.  Yet the warning still appears.

This is unfortunate, since autoconf generates config.h files with the following code (which are expected to be #included before any other files):

/* Define to empty if `const' does not conform to ANSI C. */
#define const

Autoconf relying on being able to define "const" to nothing appears to
generate these warnings.

I'm not sure whether autoconf or gcc is in the wrong on this point --
does anyone have any guidance as to who might be doing the wrong

Thanks for your time!

Best of luck,
Mark Schreiber
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20041111/7106661f/attachment.sig>

More information about the Gcc-help mailing list