Harti Brandt <[EMAIL PROTECTED]> wrote: > > Well, I just had a long discussion with a collegue about the topic. The > main problem is in the ISO-C standard, section 6.7 point 4 which states: > > All declarations in the same scope that refer to the same object or > function shall specify compatible types. > > This makes any fiddeling with a pointer of a type, that is different from > the type of the variable illegal. It also makes fiddeling with unions and > structs illegal. As far as I understand types are compatible when they > have the same type and type qualifiers. Structs are partly compatible when > they start with fields of the same type. So the only way to legally swap > integer values of any size is via arithmetic. Of course unions and > pointers may work with the given compiler version and optimisation level. > But, nothing in the standard guarantees you anything.
That's it exactly! > > It may be possible that 6.5 (7) the last sentence allows you to access your > 32-bit or 64-bit value character-wise (although I'm not sure). > > harti > The C99 standard does seem to add an "exception" for access via character pointers. The C89 standard did not have that clause. As far as the union question - the answer is that you cannot "read" from a union from a different member than it was "stored" to. For example: char ch; union { int x; char c; } my_union; my_union.x = 10; ch = my_union.c; Technically, this is illegal in ANSI C, and not guaranteed to "work". Although it will likely "work" in just about every reasonable environment. (For some definition of "work" :-) ) - Dave Rivers - -- [EMAIL PROTECTED] Work: (919) 676-0847 Get your mainframe programming tools at http://www.dignus.com To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message