'char **' <-> 'unsigned char **' and aliasing/punning in C / GNU C

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm wondering if the following is valid C, and/or valid GNU C.
Something like:

/* Returns a new malloced buffer in *OUTP.  */
void target_read_memory (unsigned long addr, int len,
                         unsigned char **outp);

void bar ()
{
  char *str;

  ...
  target_read_memory (addr, len, (unsigned char **) &str);
                                 ^^^^^^^^^^^^^^^^^^^^^^^

  // follows uses of str as a C string
  strlen (str); sscanf (str, ...);
}

chars are involved, but the cast is from a pointer to pointer,
to another pointer to pointer, so I end up confused whether
the char-aliases-everything rule kicks in around "str".

gcc doesn't complain even with -fstrict-aliasing -O3, and I can imagine
that if this didn't work, the world would break, but, from a language
perspective, is that actually valid?  If not, does gcc support this
as a GNU C extension?

-- 
Pedro Alves


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux