Re: Warning

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

 



On 5/12/08, Andrew Haley <aph@xxxxxxxxxx> wrote:
> JJ wrote:
>  > Ex2:   char_array audience;
>  >        thing_array var_list;
>  >        var_list = (thing_array&)audience;
>  >
>  > - From google'ing I found the work-a-round for Ex1 to remove the above
>  > warning,

> Removing the warning won't solve your problem: it's a real bug and
>  may well cause your program to crash or worse.

Indeed. On many architectures, different-sized data objects need to be
aligned differently in memory, on pain of bus errors or garbled data.

If for some reason it *must* access data objects out of a char array,
a conservative assumption is that basic data types must be aligned to
a multiple of their size.

For example, a char array that will be accessed through (uint32_t *) pointers:

uint8_t srtp_ciphertext[38] __attribute__((aligned(32))) = {
     0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
     0xca, 0xfe, 0xba, 0xbe, 0x4e, 0x55, 0xdc, 0x4c,
     0xe7, 0x99, 0x78, 0xd8, 0x8c, 0xa4, 0xd2, 0x15,
...

but yes, a better fix would be for the code not to do this sort of thing at all.

    M

[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