Re: syntax errror
On 2005-12-09, Daniel Rudy <spamthis@spamt his.net> wrote:[color=blue]
> At about the time of 12/4/2005 10:38 AM, Chris Torek stated the following:
>[color=green]
>> (You can also define new types with "union" and "enum", but the
>> latter two are limited; "struct" is not. Being unlimited is often
>> a mixed blessing -- "goto" is unlimited while structured looping
>> constructs like "for" and "while" are limited -- but in this case,
>> doing a cost/benefit analysis for struct vs union-or-enum usually
>> results in choosing "struct", at least for me.)[/color]
>
> Actually, unions have their place. The ability to take a int and break
> it into bytes in quite useful at times.
>
> union __break_int_tag
> {
> unsigned int integer;
> unsigned char bytes[sizeof(integer)];
> }
>
> But then portability issues arise when you do this because of the
> endiness of the machine.[/color]
Actually, they may or may not arise sometime after you do this. It
affects strict conformance only when your output depends on the values
of the bytes after storing the int [or vice versa] It only invokes
undefined behavior if and when you attempt to store an unobserved bit
pattern into the bytes and then read the int.
On 2005-12-09, Daniel Rudy <spamthis@spamt his.net> wrote:[color=blue]
> At about the time of 12/4/2005 10:38 AM, Chris Torek stated the following:
>[color=green]
>> (You can also define new types with "union" and "enum", but the
>> latter two are limited; "struct" is not. Being unlimited is often
>> a mixed blessing -- "goto" is unlimited while structured looping
>> constructs like "for" and "while" are limited -- but in this case,
>> doing a cost/benefit analysis for struct vs union-or-enum usually
>> results in choosing "struct", at least for me.)[/color]
>
> Actually, unions have their place. The ability to take a int and break
> it into bytes in quite useful at times.
>
> union __break_int_tag
> {
> unsigned int integer;
> unsigned char bytes[sizeof(integer)];
> }
>
> But then portability issues arise when you do this because of the
> endiness of the machine.[/color]
Actually, they may or may not arise sometime after you do this. It
affects strict conformance only when your output depends on the values
of the bytes after storing the int [or vice versa] It only invokes
undefined behavior if and when you attempt to store an unobserved bit
pattern into the bytes and then read the int.
Comment