public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* #define const before including system headers?
@ 2004-11-11  9:11 Mark Schreiber
  0 siblings, 0 replies; only message in thread
From: Mark Schreiber @ 2004-11-11  9:11 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1251 bytes --]

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
thing?

Thanks for your time!

-- 
Best of luck,
Mark Schreiber

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-11-11  9:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-11  9:11 #define const before including system headers? Mark Schreiber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).