generalized lvalues -- patch outline

Eric Botcazou ebotcazou@libertysurf.fr
Tue Nov 23 16:50:00 GMT 2004


> The average C programmer would not have thought to use this extension
> unless they just decided one day to try it or they actually read the
> gcc documentation (which I know almost nobody does).

I disagree: *((int *)p)++ was accepted by virtually all the good old 
compilers: GCC 2.x, Microsoft, Borland, Watcom.  This is a natural idiom when 
you're manipulating images with different color depths:

  char *p = bitmap->data;

  switch (color_depth)
  {
    case 8:
      *p++ = c;
      break;

    case 15:
    case 16:
      *((short *)p)++ = c;
      break;

    case 32:
      *((int *)p)++ = c;
      break;
   } 

Of course, nowadays everything is 32-bit so... :-)

And

char *a1 = (char*)a;
a1 += sizeof(int)/sizeof(char);
a = (typeof(a))(a1);

is plain ugly.

-- 
Eric Botcazou



More information about the Gcc mailing list