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

Re: Alignment



>If I cast a const char * such as "MiNT" or "LIVE" to a long *, shouldn't
>the compiler store the string so that it is aligned to a long boundary?
No. If the object is declared as char * (with or without const) it can
be aligned on any byte boundary by a 68K compiler.  Therefore it may
be odd.  Casting to long* makes no difference, the compiler is not going
to then move the string to align it.

>Otherwise, when trying to read the long at that address, it could be on
>an odd address, and the machine dies.
Address Error.

>Lately, that is the way I've been reading strings to compare to cookie tags.
>It has always worked, but when I changed main.c in mint, it crashes and I'm
>pretty sure its because the 68K can't read a long from an odd address.  Is
>this a bug in the compiler, or is such a cast simply bad programming?
Bad programming, I'm afraid.