Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

A block comment in C is a lexical construct used to instruct the preprocessor and compiler to ignore an arbitrary span of source text. It is delimited by specific character sequences and can span multiple lines or exist inline within a single statement.

Syntax

A block comment begins with the forward-slash asterisk sequence /* and terminates with the first subsequent asterisk forward-slash sequence */.
/* Single-line block comment */

/*
   Multi-line
   block comment
*/

int x = 10 /* Inline block comment */ + 5;

Lexical Rules and Compiler Behavior

  • Token Replacement: During translation phase 3 of the C compilation process, the preprocessor replaces the entire block comment (including its delimiters) with a single space character. Consequently, block comments cannot be used to concatenate adjacent tokens.
int foo/* comment */bar = 0; // Evaluates to: int foo bar = 0; (Syntax Error)
  • String Literals and Character Constants: The /* and */ character sequences lose their special meaning when enclosed within string literals (" ") or character constants (' '). The compiler treats them as standard character data rather than comment delimiters.
char* str = "This is not a /* comment */"; // The delimiters are parsed as string characters
  • Line Splicing: If a line splice (a backslash \ immediately followed by a newline) occurs within a block comment, the compiler processes the splice during translation phase 2, prior to parsing the comment delimiters.

Nesting Constraints

Standard C strictly prohibits the nesting of block comments. The lexical analyzer terminates the comment at the very first */ sequence it encounters, regardless of how many /* sequences preceded it. Attempting to nest block comments exposes the remaining text to the compiler, typically resulting in a syntax error when it attempts to parse the trailing, unmatched */.
/* Outer comment starts
   /* Inner comment starts */ 
   This text is now exposed to the compiler and will cause a syntax error.
*/ 
Master C with Deep Grasping Methodology!Learn More