[Bug regression/40665] dereferencing type-punned pointer warnings cannot be disabled

pinskia at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Tue Jul 7 18:18:00 GMT 2009



------- Comment #11 from pinskia at gcc dot gnu dot org  2009-07-07 18:18 -------
(In reply to comment #10)
> For example, you write "unsigned char *framebuffer = vga_getgraphmem();" and
> now you want to access the framebuffer. According to the standard, you could
> only do it by bytes. But that means one bus cycle to the videocard for every
> byte transfered. So people understand that common processors allow aligned
> accesses to 2, 4 or 8 bytes and that common videocards have their framebuffer
> base address aligned on same larger boundary --- and they simply cast the
> pointer to u_int32_t or u_int64_t and access the videoram faster. Each time you
> watch some video, remember those undefined memory accesses that are hapenning
> for you to get faster performance :)

Not fully, you missed part of the standard that takes about the effective type. 
Basically if there is no declared type for an object, the effective type is the
type which is used for storing and then only that can be read back with that
type or character type or the other cases the standard mentions.  The effective
type changes when another store happens.

In both of original cases in this bug report, there is a declared type which is
also the effective type.

And it is not about the cast between the pointer types which causes it to be
undefined but rather the accesses.  


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40665



More information about the Gcc-bugs mailing list