Output undefined?

Discussion in 'C Programming' started by no@no.no, Oct 1, 2003.

  1. Guest

    main()
    {
    int i;
    printf("%d %d",i++,++i);
    }

    Is the output undefined?

    int main #include crap etc. is understood.
    , Oct 1, 2003
    #1
    1. Advertising

  2. On Wed, 01 Oct 2003 16:53:56 +0200, n wrote:


    > int i;
    > printf("%d %d",i++,++i);


    > Is the output undefined?



    Yes because you have never given i a value.

    And that's before considering in which order i++ and ++i will be evaluated.

    --
    NPV
    "Linux is to Lego as Windows is to Fisher Price." - Doctor J Frink
    Nils Petter Vaskinn, Oct 1, 2003
    #2
    1. Advertising

  3. Richard Bos Guest

    "Nils Petter Vaskinn" <> wrote:

    > On Wed, 01 Oct 2003 16:53:56 +0200, n wrote:
    >
    > > int i;
    > > printf("%d %d",i++,++i);

    >
    > > Is the output undefined?

    >
    > Yes because you have never given i a value.
    >
    > And that's before considering in which order i++ and ++i will be evaluated.


    Order is immaterial; the mere occurence of them both together between
    sequence points invokes undefined behaviour.

    If either of you had read the FAQ, you'd have known this:
    <http://www.eskimo.com/~scs/C-faq/q3.2.html>.

    Richard
    Richard Bos, Oct 1, 2003
    #3
  4. Dan Pop Guest

    In <> "Nils Petter Vaskinn" <> writes:

    >On Wed, 01 Oct 2003 16:53:56 +0200, n wrote:
    >
    >
    >> int i;
    >> printf("%d %d",i++,++i);

    >
    >> Is the output undefined?


    Read the FAQ!

    >Yes because you have never given i a value.
    >
    >And that's before considering in which order i++ and ++i will be evaluated.


    The evaluation order does NOT matter. What matters is the lack of a
    sequence point between these two expressions. So, instead of having an
    unspecified output (assuming a properly initialised i) we have undefined
    behaviour for the whole program. The FAQ clearly explains these issues!

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, Oct 1, 2003
    #4
  5. Jack Klein Guest

    On Wed, 01 Oct 2003 16:53:56 +0200, wrote in comp.lang.c:

    > main()
    > {
    > int i;
    > printf("%d %d",i++,++i);
    > }
    >
    > Is the output undefined?
    >
    > int main #include crap etc. is understood.
    >


    Yes, even if you initialized I with a value. There is no sequence
    point in the evaluation of arguments to functions, so your code
    modifies i twice without an intervening sequence point.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
    Jack Klein, Oct 1, 2003
    #5
  6. Default User Guest

    wrote:

    > int main #include crap etc. is understood.


    It would have taken less typing to just to do it right in the first
    place.



    Brian Rodenborn
    Default User, Oct 1, 2003
    #6
  7. Default User <> scribbled the following:
    > wrote:
    >> int main #include crap etc. is understood.


    > It would have taken less typing to just to do it right in the first
    > place.


    I agree. I detect a shade of DAISNAID. Oh, sorry, forgot that
    abbreviations are frowned upon here. "Do As I Say, Not As I Do".

    --
    /-- Joona Palaste () ---------------------------\
    | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
    | http://www.helsinki.fi/~palaste W++ B OP+ |
    \----------------------------------------- Finland rules! ------------/
    "You have moved your mouse, for these changes to take effect you must shut down
    and restart your computer. Do you want to restart your computer now?"
    - Karri Kalpio
    Joona I Palaste, Oct 1, 2003
    #7
    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. Jim Owen

    Output parameters undefined? Huh?

    Jim Owen, Oct 22, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    412
    Rajesh.V
    Oct 22, 2003
  2. Alex Vinokur
    Replies:
    1
    Views:
    442
    Alf P. Steinbach
    Sep 27, 2004
  3. Mantorok Redgormor
    Replies:
    70
    Views:
    1,723
    Dan Pop
    Feb 17, 2004
  4. VK
    Replies:
    45
    Views:
    573
    Dr John Stockton
    Sep 12, 2006
  5. -Lost
    Replies:
    13
    Views:
    355
    Richard Cornford
    Jan 31, 2007
Loading...

Share This Page