Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Nested Comments

Part of TutorialIntermediate

Description

This program doesn't do anything, but it's well-documented.

Example

/* 

This program demonstrates using comments in D.

(Such as the multi-line comment this sentence resides in.)

*/



/+   

    This is one of D's nested comments.  


    /+ What would an example of a nested comment be without 
       a nested (and /+ another nest +/ )comment? +/

    /* Naturally, you can also put something like this in a nested multiline comments... */

    // as well as text like like this ...

    /* since the compiler is only concerned about being in a nested comment block,
        you don't actually need a matching * and / to satisfy the compiler.

+/


void main()  
{ // This is a single line comment.  It automatically ends at the end of the line.
}

Types of Comments in the D Programming Language

There are three different kinds of comments in D.

(1) Single-line comments (//):

These comments can start anywhere except in the middle of a token and continue until the end of the line.

(2) Regular multi-line comments (/* */):

These comments can occur anywhere except within a token or another regular multi-line comments.

(3) Nesting multi-line comments (/+ +/):

These comments can occur anywhere except within a token. Whenever the compiler sees an initial marker (/+), it goes into "nesting comments" mode. At this point, the compiler is only looking for two things another initial marker to indicate a deeper nested comment or a terminal marker (+/) to close a nesting level. The compiler ignores other symbols within nested comments including quotes(""), multi-line comments (/* */), and single-line comments (//).

Source

Link http://jcc_7.tripod.com/d/tutor/intermediate/nested_comments.html
Author jcc7