Thread: Strange!!

  1. #16
    Registered User
    Join Date
    Aug 2011
    Posts
    385
    Quote Originally Posted by rags_to_riches View Post
    Did you go to the link???????????
    Yes I did. Hence deleted the post. The last line says it is free....

  2. #17
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by JohnGraham View Post
    Except in this statement:
    fun() will give you A value, but it's not the RETURNED value, because there was no returned value at all.

    Since X was the only value in fun(), it gets printed. In those days, every function returned an int, unless specified otherwise. If no return was given, TC supplied the (iirc), last data it worked with in the function, as an int.

    Those C89 and 99 standards were NOT the AT&T standards, as followed by Turbo C.
    Last edited by Adak; 12-05-2011 at 10:44 AM.

  3. #18
    Registered User
    Join Date
    Aug 2011
    Posts
    385
    pelles C outputs x=1.

  4. #19
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    this has nothing to do with C99. your ancient TurboC compiler simply allows erroneous code and as CTater said, it just happened that the registers worked out to leave the value of X in the right place. If you don't believe it, just use your debugger to step through the code at assembly level.

    edit: what i meant by 'nothing todo with C99', I meant C89 should complain and refuse to compile also.
    Last edited by dmh2000; 12-05-2011 at 10:50 AM.

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Adak
    fun() will give you A value, but it's not the RETURNED value, because there was no returned value at all.

    Since X was the only value in fun(), it gets printed. In those days, every function returned an int, unless specified otherwise. If no return was given, TC supplied the (iirc), last data it worked with in the function, as an int.
    You stated that there was no returned value, then you observe that a value was printed. Clearly, that value is the return value, despite the lack of a return statement. As such, when we analyse the program with respect to the C standard, the behaviour is undefined.

    Quote Originally Posted by Adak
    Those C89 and 99 standards were NOT the AT&T standards, as followed by Turbo C.
    I do not think AT&T ever standardised C, unless you are talking about K&R as a de facto standard. In any case, your disagreement is misplaced. You would have been better off agreeing and then pointing out that Turbo C was implemented before the C standard was published.
    Last edited by laserlight; 12-05-2011 at 11:05 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange bug....
    By beene in forum C++ Programming
    Replies: 4
    Last Post: 10-11-2006, 11:55 AM
  2. Strange !!!
    By Moni in forum C++ Programming
    Replies: 19
    Last Post: 01-05-2004, 01:48 PM
  3. Very strange bug...
    By JaWiB in forum Tech Board
    Replies: 6
    Last Post: 04-27-2003, 01:56 PM
  4. strange strange functions
    By threahdead in forum C Programming
    Replies: 4
    Last Post: 10-13-2002, 05:31 PM
  5. strange
    By pode in forum C++ Programming
    Replies: 4
    Last Post: 06-08-2002, 12:07 PM