[PATCH:libX11 1/2] Bug 32098: Making XInternAtoms take const char ** breaks callers

Simon Thum simon.thum at gmx.de
Thu Dec 16 14:20:52 PST 2010


On 12/15/2010 08:15 PM, Aaron Plattner wrote:
> $ gcc test.c
> test.c: In function ‘main’:
> test.c:11: warning: initialization from incompatible pointer type
> $ ./a.out
> x
> $ gcc -O2 test.c
> test.c: In function ‘main’:
> test.c:11: warning: initialization from incompatible pointer type
> $ ./a.out
> a
> 
Indeedubitably.

But what does it show? It shows you can shoot yourself in the foot, with
cheering applause from the compiler. No news here.

Something more to the point:

void callmeconst(const char * const * arg) {
   printf("%s\n", *arg);
}

void main(void) {
  char* cp = "s";
  char** pp = &cp;
  callmeconst(pp);
  callmeconst(&cp);
}

yielding

warning: passing argument 1 of ‘callmeconst’ from incompatible pointer type
note: expected ‘const char * const*’ but argument is of type ‘char **’

times two but as least it doesn't fail to compile. Sure, you'd have to
wait for the standard to catch up or something equally desirable to get
rid of the warning, but I think it's a not-too-remote option.

Cheers,

Simon


More information about the xorg-devel mailing list