Single line comments in Ansi-C

ANSI-C, no, but the current standard revision allows them, and has done so ever since C99.


Sorry but it looks like in ANSI-C only /* comment */ are used. http://members.cox.net/midian/articles/ansic1.htm


You could also write a macro:

#define COMMENT(x)

int main() {
   COMMENT(Hi there)
   return 0;
}

Other than that nothing obvious in ANSI C - you're correct in noting that /* */ style is not valid in ANSI C 89


Well ...

ANSI C is C99; and it allows comments starting with // extending to the end of the line.
In the previously published standard (C89/C90) the // comments weren't described (but many compilers accepted them as an extra anyway).

You have yet another option for commenting: the #if 0 / #endif construction (usually used for commenting out "inactive" code)

/* ... */
#if 0
This is a comment
#endif
/* ... */

Tags:

C

Gcc