Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Help wanted on some source codes

Reply
Thread Tools

Help wanted on some source codes

 
 
Becker
Guest
Posts: n/a
 
      11-30-2005
Thanks all
Yes, I understand now. The codes are full of undifined behaviors.
And If I want to know why the results are like that, I should
get to know how gcc treats those "undifined behaviors".

PS: I get those programs from a forum

 
Reply With Quote
 
 
 
 
Allin Cottrell
Guest
Posts: n/a
 
      11-30-2005
Jack Klein wrote:

> Friends don't let friends void main().


I like it! Looks like sig material to me.

Allin Cottrell
 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      11-30-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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.
 
Reply With Quote
 
Becker
Guest
Posts: n/a
 
      11-30-2005

Flash Gordon wrote:
>
> 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.


hehe, I got it.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need some help for source codes about keep data secret management system baseed on C/S architecture lovesehuang@yahoo.com.cn C++ 2 01-03-2007 06:37 AM
Virtual Key Codes, Scan Codes and ASCII Codes in C gj_williams2000@yahoo.co.uk C Programming 2 08-20-2005 11:04 AM
Data Recovery SOURCE CODE ( SOURCE CODES of Professional Data Recovery Software ) Author Tarun Tyagi Cisco 0 12-29-2004 05:03 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 1 07-16-2004 01:12 PM
HELP WANTED HELP WANTED HELP WANTED Harvey ASP .Net 0 07-16-2004 10:00 AM



Advertisments