Single comment line without C99?

This is a discussion on Single comment line without C99? within the C Programming forums, part of the General Programming Boards category; For several years I've been use to the single ('//') comment line in C++. I know in C89 this isn't ...

  1. #1
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283

    Single comment line without C99?

    For several years I've been use to the single ('//') comment line in C++. I know in C89 this isn't standard, but it is in C99. Is it common to use it anyway? Is it widely portable? Thanks.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No. If you want to be portable, use:

    /* single line comment */

    Otherwise, you have to hope it's right for your particular compiler, which by definition, means "not portable".


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    Makes sense. I guess it's in the C spirit too

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,273
    It's true that it's a C99 standard, but by doing it, you basically force everyone to have a C99 compiler in order to compile your program, and at that, you are forcing them to do this just because of how some COMMENTS are written.

    I'd say this: if you are already using other language features which require C99 compliance, then feel free to use all of C99 as you wish, including the //-style comments. But don't do it if that's ALL you are using from C99.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    Got it. And nice to meet another Portlander!

  6. #6
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    /* Put comments in your code like this. */
    // Because your code won't always compile if you put comments in like this

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very strange error...
    By Blackroot in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2006, 01:37 AM
  2. print line by line from a file
    By SoFarAway in forum C Programming
    Replies: 3
    Last Post: 02-18-2005, 01:36 PM
  3. if is faster than switch?
    By skorman00 in forum C++ Programming
    Replies: 32
    Last Post: 03-06-2004, 01:15 PM
  4. Random Line (pls comment)
    By sikamikaniko in forum C++ Programming
    Replies: 9
    Last Post: 03-16-2003, 02:47 PM
  5. Greenhand want help!
    By leereg in forum C Programming
    Replies: 6
    Last Post: 01-29-2002, 06:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21