Re: Help wanted on some source codes
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 30 Nov 2005 08:24:06 +0000
slebetman@xxxxxxxxx wrote:
Old Wolf wrote: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.
The programs are rubbish of course. But wouldn't the file scope of x mean that function f() is actually refering to the double x instead of the int x?
No, both variable x have external linkage therefore the behaviour is undefined and on some systems, with some options, won't even link. If it does link the compiler is allowed to put both items in the same location, make that location the size of the smaller (probably int) and send a letter to you mother telling her you are dead. Alternatively the compiler/linker could place the two variables in separate locations and send a letter to the accounts department of the company you work for telling them to stop your salary. Anything it does is valid.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
.
- References:
- Help wanted on some source codes
- From: Becker
- Re: Help wanted on some source codes
- From: Old Wolf
- Re: Help wanted on some source codes
- From: slebetman@xxxxxxxxx
- Help wanted on some source codes
- Prev by Date: Re: Help wanted on some source codes
- Next by Date: Re: Advanced C
- Previous by thread: Re: Help wanted on some source codes
- Next by thread: Re: Help wanted on some source codes
- Index(es):
Relevant Pages
|