Thread: semicolon usage?

  1. #1

    Question semicolon usage?

    I was woundering since my last thread, is there any exception to the semicolon at the end of every line except for when you define a function and when you start and end that function with the { } marks?

  2. #2
    It isn't that I think of it as a rule. It is because I just came from using Ruby and I am not use to the semicolon at the end of the line thing.

  3. #3
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187

    Re: semicolon usage?

    is there any exception to the semicolon at the end of every line
    1. Semi-colon is not placed at the end of line, but at the end of statement. So one line can contain many statements.
    2. When you define a function body likes int foo() { stuff }.. you must not put semi-colon after (). But when you declare prototypes, you need it at the end of prototypes.
    3. When you initialize array, define enum, class and so on with { at beginning, you need semi-colon after }.
    4. This may not cover all usage of semi-colon, just remember in C semi-colon is as a terminator. Some language likes pascal semi-colon is as a separator.
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    some other "rules":

    don't use semicolons after conditional statements:

    if(true);//wrong
    while(infile >> num);//wrong;

    do use semicolons after declarations of types whether typedefs, structs, classes, functions.

    Basically, no single rule, but you learn the syntax reasonably fast.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Net cpu usage of pthreads?!
    By mynickmynick in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2008, 07:59 AM
  2. Memory usage and memory leaks
    By vsanandan in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 05:45 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Calculating CPU Usage
    By vitaliy in forum Linux Programming
    Replies: 3
    Last Post: 08-21-2005, 09:38 AM
  5. Win2K Limiting CPU Usage?
    By drdroid in forum Tech Board
    Replies: 4
    Last Post: 03-31-2004, 02:08 PM