B
Becker
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;
}
2.===========================================
/* a.c */
int x = 1;
int y;
void main()
{
f();
printf("%x %x\n", x, y);
}
/* b.c */
double x;
void f()
{
x = -0.0;
}
3.===========================================
/* a.c */
int x;
int y = 1;
void main()
{
f();
printf("%x %x\n", x, y);
}
/* b.c */
double x;
void f()
{
x = -0.0;
}
4.===========================================
/* a.c */
int x = 1;
int y = 1;
void main()
{
f();
printf("%x %x\n", x, y);
}
/* b.c */
double x;
void f()
{
x = -0.0;
}
5.===========================================
/* a.c */
int x = 1;
int y = 1;
void main()
{
f();
printf("%x %x\n", x, y);
}
/* b.c */
double x;
void f()
{
x = -0;
}
Remark=======================================
The above programs from 1 to 5 are all constituted
of two separate files, a.c & b.c, and can be
compiled under gcc.
e.g.
/* Linux */
$ gcc -o test a.c b.c
$ ./test
/* Windows */
C:\gcc -o test.exe a.c b.c
C:\test
Question=======================================
I'm wondering about the strange results generated
by the programs. Please help me. I want to understand
why the results are like that.
By the way, the source codes above are in old K&R style
and will be warned by the gcc, you can change them to
new ISO/ANSI style
Thanks in advance & best regards!
Becker
30-Nov-2005
/* a.c */
int x;
int y;
void main()
{
f();
printf("%x %x\n", x, y);
}
/* b.c */
double x;
void f()
{
x = -0.0;
}
2.===========================================
/* a.c */
int x = 1;
int y;
void main()
{
f();
printf("%x %x\n", x, y);
}
/* b.c */
double x;
void f()
{
x = -0.0;
}
3.===========================================
/* a.c */
int x;
int y = 1;
void main()
{
f();
printf("%x %x\n", x, y);
}
/* b.c */
double x;
void f()
{
x = -0.0;
}
4.===========================================
/* a.c */
int x = 1;
int y = 1;
void main()
{
f();
printf("%x %x\n", x, y);
}
/* b.c */
double x;
void f()
{
x = -0.0;
}
5.===========================================
/* a.c */
int x = 1;
int y = 1;
void main()
{
f();
printf("%x %x\n", x, y);
}
/* b.c */
double x;
void f()
{
x = -0;
}
Remark=======================================
The above programs from 1 to 5 are all constituted
of two separate files, a.c & b.c, and can be
compiled under gcc.
e.g.
/* Linux */
$ gcc -o test a.c b.c
$ ./test
/* Windows */
C:\gcc -o test.exe a.c b.c
C:\test
Question=======================================
I'm wondering about the strange results generated
by the programs. Please help me. I want to understand
why the results are like that.
By the way, the source codes above are in old K&R style
and will be warned by the gcc, you can change them to
new ISO/ANSI style
Thanks in advance & best regards!
Becker
30-Nov-2005