Thread: More places for the semi-colen!

  1. #16
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    So far we've got the following cases where a semicolon is required to avoid ambiguity:
    - Post increment and pre-increment.
    - End of a struct, union or enum declaration.
    - Empty statements.

    Are there any others?

    One could argue that these three situations could easily be redesigned. For example, by introducting a keyword for empty statements (this would improve clarity and readability anyway) and using a different sequence for the post and pre inc/decrement operators.

  2. #17
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    >> the fact that you have to use them at all is annoying - omitting them wouldn't create
    >> any ambiguities for the parser that I can think of...so why should they be required?

    Not really, if you didn't have them you couldn't do any command stacking:

    int i = 0; myFunc(i); i++; myFunc(i);

    >> What benefit do you see arising from this? I mean, why did you make it a habit?

    Nothing, it wasn't deliberate.

    Thantos, Both of you'r examples INVOLVE if-else statements, in whitch cases I never use unless I need to.
    Last edited by Queatrix; 02-22-2006 at 05:50 PM. Reason: Adding stuff!

  3. #18
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by Cool-August
    Not really, if you didn't have them you couldn't do any command stacking:

    int i = 0; myFunc(i); i++; myFunc(i);
    You should read the replies, as someone suggested they could be eliminated with rules requiring an operator between data otherwise it's a new statement.

    Code:
    a + b * c   d = e
              ^
         No operator
         this starts a new statement
    which was then replied with the exception of unary operators such as increment (++) and decrement (--)
    Sent from my iPad®

  4. #19
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46
    Hmmm, did anyone think about the fact that it would KILL READABILITY.
    I like simicolons, they let me know when someone is ending a statement and
    to me, they are a blessing when I code. What good would it do if you're writing code
    and you have to go back up five lines and you have no idea what you were doing?
    Also, a lot of people, I'm sure, like simicolons, and in addition everyone would
    have to learn how to code WITHOUT them.

  5. #20
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by Cool-August
    >> the fact that you have to use them at all is annoying - omitting them wouldn't create
    >> any ambiguities for the parser that I can think of...so why should they be required?

    Not really, if you didn't have them you couldn't do any command stacking:

    int i = 0; myFunc(i); i++; myFunc(i);
    You're missing the point.

    Code:
    int i = 0 myFunc(i)  i++  myFunc(i)
    This code isn't ambiguous. But as we have seen, there are some potential ambiguities involving the ++ operator.

    EDIT: Missed Maelstrom's reply.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  6. #21
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I realized that you can place a semi-colen after brackets.
    Not after do-while loops you can't.
    Code:
    do {
    }; while(1);
    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

Similar Threads

  1. Decimal places
    By Gordon in forum Windows Programming
    Replies: 9
    Last Post: 06-08-2008, 09:04 AM
  2. Decimal places
    By Gordon in forum Windows Programming
    Replies: 4
    Last Post: 09-28-2007, 10:03 AM
  3. Replies: 1
    Last Post: 12-14-2002, 01:51 AM
  4. Replies: 10
    Last Post: 06-12-2002, 03:15 PM
  5. online gaming places
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 02-20-2002, 12:26 AM