Re: Help wanted on some source codes



Becker wrote:

> 1.===========================================
> /* a.c */
> int x;
> int y;
>
> void main()
> {
> f();
> printf("%x %x\n", x, y);
> }
>
> /* b.c */
> double x;
>
> void f()
> {
> x = -0.0;
> }

All of your programs have undefined behaviour because there
are two variables called 'x' with external linkage.

Also, "%x" is only to be used for unsigned ints, and
main should return an int (allowing "void main" is compiler-
specific).

For an understanding of why GCC gives the results you see,
please ask your question on a GCC newsgroup.

.



Relevant Pages