Newsgroups trimmed to comp.lang.c
Paul Lutus said:
Gerry said:
[My apologies for accidental double post on comp.lang.c. Mr. Lutus is
now attempting to escape his embarrasment by silently changing follow-
ups.]
Keith Thompson wrote:
Paul Lutus <
[email protected]> writes:
typedef union abc
{ int x;
float y;
} a_union;
2. This is not a union, it it two instances of the same variable.
Again, to reply to my post, you need to provide the Java bytecode that
unites a Java float and a Java integer in the same address space,
something that is not allowed in Java.
Of course it's a union. It has two members x and y which are in this
instance of different types, although that is by no means part of the
specification.
Yes, it is a union in C, but I am saying it is not a union in the Java
bytecode. You have made this appear to be the meaning of my statement by
concatenating two unconnected parts of posts, creating the illusion of a
sequence that was not present in the original.
Ok, it's not a union in the Java bytecode because there's no such
thing as a union in Java bytecode. For a C compiler that generates,
say, x86 machine code, there will be no union in the generated code
because there's no such thing as a union in x86 machine code. A union
is a C construct; it's the compiler's job to generate code for the
target system that implements the union. As far as I can tell, the
compiler in question does exactly that. (Details about what the Java
bytecode looks like might be interesting, but are off-topic here.)
This intentional misquote unermines your entire post. My statement is
clearly that, since Java doesn't support anything like a union, the product
doesn't create unions as its output, it can only read them from the C
source and then figure out what to do with them.
Yes, that's exactly what a compiler does.
And just to make the distinction clear, what the Java language
supports is irrelevant; we're talking about what Java bytecode
supports. The language and the bytecode are two different things, and
it's unfortunate that the same name is used for both. They were
designed together, but Java can be compiled to forms other than Java
bytecode, and languages other than Java can be compiled to Java
bytecode.
What it produces in Java
bytecode is not a union.
Of course not; I wouldn't expect it to be.
And, more to the point, what it does produce
behaves differently than the original C code does.
C code by itself has no behavior until it's compiled and executed.
The behavior of a C program that writes to one member of a union and
then reads from another member of the same union is, except in some
limited cases, undefined. And, more to the point, the behavior
indicated by Mohd Hanafiah Abdull several articles upthread was
consistent between MPC and gcc (except for some extra trailing zeros;
I'm not sure which one is correct there, but it's beside the point).
Again, here's the output he posted:
] MPC produced:
] int val = 1078531719
] float val = 3.142
] int val = 1078531719
] float val = 3.142
]
] gcc produced:
] int val = 1078531719
] float val = 3.142000
] int val = 1078531719
] float val = 3.142000
I got the same results myself using gcc on an x86 system; it's
consistent with overlaying a 32-bit integer with a 32-bit IEEE
floating-point value.
So, what exactly were you complaining about?