Function return value automatically

Discussion in 'C Programming' started by chellappa, Nov 23, 2005.

  1. chellappa

    chellappa Guest

    hi
    this program return value automatically ... how it is possible ..i am
    not return any value... but i return correct values
    i am using Linux -gcc complier
    please tell me what is this
    main()
    {
    int a,b,c,sum;
    printf("ENTER ANY THREE NUMBERS :\n");
    scanf("%d%d%d",&a,&b,&c);
    sum=rAJAsum(a,b,c);
    printf("sum = %d\n", sum);
    }
    calsum(x,y,z)
    int x,y,z;
    {
    int d;
    dSD=x+y+z;
    }

    Output:
    --=====
    ENTER ANY THREE NUMBERS :
    23
    23
    23
    sum = 69

    Thanks All
    by
    Chellappa
     
    chellappa, Nov 23, 2005
    #1
    1. Advertising

  2. On 23 Nov 2005 07:26:06 -0800, in comp.lang.c , "chellappa"
    <> wrote:

    >hi
    >this program return value automatically ... how it is possible ..i am
    >not return any value... but i return correct values


    By complete chance. You're declaring a function calsum which
    implicitly returns an int, and the last value on the stack happens to
    be the sum of x,y, and z, so that gets returned. This is random
    nonsense.

    This is a horrible, horrible programme. It uses a style of C that was
    obsoleted more than 15 years ago. Stop doing that, learn proper modern
    C.

    >main()


    main should be declared
    int main(void) or int main(int, char**)

    >calsum(x,y,z)
    >int x,y,z;


    This style of declaration is obsolete and possibly even illegl. Please
    learn proper C.

    int calsum(int x, int y, int z)
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Nov 24, 2005
    #2
    1. Advertising

  3. Mark McIntyre <> writes:
    > On 23 Nov 2005 07:26:06 -0800, in comp.lang.c , "chellappa"
    > <> wrote:
    >
    >>hi
    >>this program return value automatically ... how it is possible ..i am
    >>not return any value... but i return correct values

    >
    > By complete chance. You're declaring a function calsum which
    > implicitly returns an int, and the last value on the stack happens to
    > be the sum of x,y, and z, so that gets returned. This is random
    > nonsense.


    It's at least equally likely that the value was in a register rather
    than on the stack.

    As far as the language is concerned, it could as easily have been left
    scrawled on a piece of paper shoved into a dictionary next to the
    entry for "gullible", which just happens to be where function return
    values are stored. Or it could be an amazing coincidence. (Neither
    of these is likely, of course.)

    But those demons certainly do clear your sinuses on the way out.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Nov 24, 2005
    #3
  4. chellappa wrote:
    > hi
    > this program return value automatically ... how it is possible ..i am
    > not return any value... but i return correct values
    > i am using Linux -gcc complier
    > please tell me what is this


    Start to fucking think on your own.



    Igmar
     
    Igmar Palsenberg, Nov 28, 2005
    #4
  5. On Mon, 28 Nov 2005 10:55:34 +0100, in comp.lang.c , Igmar Palsenberg
    <> wrote:

    >chellappa wrote:
    >> hi
    >> this program return value automatically ... how it is possible ..i am
    >> not return any value... but i return correct values
    >> i am using Linux -gcc complier
    >> please tell me what is this

    >
    >Start to f..king think on your own.


    and people complained about me saying bu...
    :)
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Nov 28, 2005
    #5
  6. Igmar Palsenberg <> writes:
    > chellappa wrote:
    >> hi
    >> this program return value automatically ... how it is possible ..i am
    >> not return any value... but i return correct values
    >> i am using Linux -gcc complier
    >> please tell me what is this

    >
    > Start to f***ing think on your own.


    [edited for content]

    First, chellappa's question has already been addressed at length.
    Since Usenet is asynchronous, it's possible you haven't been able to
    see the other replies, but if you can, please check for other
    followups before posting.

    Second, 4-letter words don't bother me personally very much, but they
    do bother some people, and they're really not necessary. If you feel
    the need to dispense some verbal abuse, try to be a bit more creative
    about it; it's possible to be insulting without using any words you
    wouldn't hear on Sesame Street.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Nov 28, 2005
    #6
  7. Mark McIntyre said:

    > On Mon, 28 Nov 2005 10:55:34 +0100, in comp.lang.c , Igmar Palsenberg
    > <> wrote:
    >
    >>Start to [expletive deleted] think on your own.

    >
    > and people complained about me saying [partial exp. del.!]...


    And some people have noticed that you've stopped doing so, and are not
    unappreciative.

    It was worthwhile to complain to you, since I know you are bright enough to
    understand the point. (Foul-mouthed non-regs simply get plonked without
    notice; it's a cost-benefit trade-off!)

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Nov 28, 2005
    #7
  8. chellappa

    Default User Guest

    Mark McIntyre wrote:

    > On Mon, 28 Nov 2005 10:55:34 +0100, in comp.lang.c , Igmar Palsenberg
    > <> wrote:


    > > Start to f..king think on your own.

    >
    > and people complained about me saying bu...


    "Butter"?



    Brian
     
    Default User, Nov 29, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Seong-Kook Shin
    Replies:
    1
    Views:
    511
    Richard Bos
    Jun 18, 2004
  2. Greenhorn
    Replies:
    15
    Views:
    868
    Keith Thompson
    Mar 6, 2005
  3. chellappa

    Function return value automatically

    chellappa, Nov 23, 2005, in forum: C Programming
    Replies:
    2
    Views:
    271
    chellappa
    Nov 23, 2005
  4. CSINVA
    Replies:
    6
    Views:
    418
    Paul Delcogliano
    Nov 7, 2007
  5. Daniel Pitts
    Replies:
    3
    Views:
    466
    Vidar Hasfjord
    Jan 31, 2009
Loading...

Share This Page