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

Re: Alignment



evanlang@uss.lonestar.org (Evan Langlois) writes:

|> 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?
|> Otherwise, when trying to read the long at that address, it could be on
|> an odd address, and the machine dies.

Casting a pointer to a pointer with more alignment restrictions is
undefined in ANSI C, and you can never expect that this works.  The
compiler is always allowed to align an object using the least
restriction as possible, and for strings (that are char[]) this is
byte alignment (for the m68k anyway).  It is impossible for the
compiler to deduce that you are planning to access it via long *,
since this could be hidden through many function calls.  Btw., on a
68020+ this will succeed nevertheless.

-- 
+------------------------------------------------------------------------+
Andreas Schwab                                      "And now for something
schwab@ls5.informatik.uni-dortmund.de                completely different"