Thread: Lost ("short int" and "while" statements)

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by dwks View Post
    Ever seen code like this?
    Code:
    for(x = 0, y = 1; ...
    That's using the comma operator.
    I have of course... in for loops.

    Same idea anywhere else: the left side is evaluated, then the right side, and the whole expression gets the value of the right side. So this
    Code:
    do
        code();
    while(expression());
    is the same as
    Code:
    do
        ;
    while(code(), expression());
    (Your compiler might want you to put extra parentheses around there, you never know. Oh, and the semicolon is necessary. )
    Now that is syntax unknown to me and syntax I've never actually seen used somewhere. Though I don't think I would ponder using it. Too obscure.
    Btw, by obscure, I mean using it in a while loop as shown there. I could use it to initialize several variables in a for loop, or to increment two counters or such in a for loop, which I've done before, but not do...while loops, like that.
    But anyway, this still means that theonetruehero mixed them up in the wrong order.
    Last edited by Elysia; 02-27-2008 at 07:46 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Yes, I wasn't saying theonetruehero's code was correct -- it isn't.

    Nor would I recommend using the comma operator in while loops. I was just pointing out that it is possible.

    I have seen the comma operator used outside of for loops, however. (Not in while loops, though.) For example:
    Code:
    if(in_position()) x ++, y ++;
    Whether you find legible and use that sort of code or not is up to you . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed