This is what "The C Programming Language" 2nd edition (Kernighan & Ritchie) says (page 199): "A pointer to one type may be converted to a pointer to another type. The resulting pointer may cause addressing exceptions if the subject pointer does not refer to an object suitably aligned in storage." When casting pointers to another type, the programmer must keep an eye on alignment. A compiler may use clever techniques to warn for possible misalignment, but it is not required to do so. Regarding the effort of examining all source code for type casts with alignment problems, my opinion is that type casts should be used sparingly. The requirement to "silence" the compiler with a type cast already means that the compiler frowned upon the statement. Thiadmer
Message
Re: For C Experts
2006-03-31 by Thiadmer Riemersma (ITB CompuPhase)
Attachments
- No local attachments were found for this message.