This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to enable nesting comments

Hello Forum,
I wanna use nesting comments with µvision/C166. How to enable them? It is really annoying to work without them.
Thanks - Peter

N.B.: Nesting comments means something like this:
/* bla bla /* This is bla */
blub blub */
All of this is a comment. Without nesting comments the comment would end just before "blub blub" and the second "*/" would end up with an error.

  • Have you been worked with this kind of comments ? What tool could you use it without problems ?

  • I used it with SAS/C and some Win-based Compiler we used at our university.
    I know, it isn't Ansi compliant, but there are som compiler (preprocessor) options to enable this style of comments.

    bye

  • I couldn't find a specific directive Peter, you can cheat and change even the character that'll be used as a comment for example.

    /* traditional comment */
    >>>> cheat comment <<<<

    I cannot found a preprocessor directive. I think that the algorithm used to find comments don't allow this kind of nesting. If the algorithm finds /* he will only stop to set the text as a comment if it finds a */ character.

  • Many compilers support such nesting of comments, and usually have an option to enable or disable it.

    Probably, the facility is more common in "bigger" compilers; eg MSVC, BCB.

    C51 doesn't support it, either. :-(

    Perhaps you could try using the Borland or MS preprocessor, and compile the result with C166.

    A common reason for using it is when commening-out a block of code; eg,

    /* disabled code
       x = 1;         /* Blah   */
       y = 2;         /* Waffle */
       z = f( x, y ); /* Tripe  */
    */

    In this case, an alternative could be:

    #if 0
       x = 1;         /* Blah   */
       y = 2;         /* Waffle */
       z = f( x, y ); /* Tripe  */
    #endif 
    

  • Thanks for the nesting comments example.

  • You can get very confused if you have a syntax-highlighting editor which handles nested comments in a slightly different way to your preprocessor!

    The safest (and ANSI-compliant) way is to avoid them!

  • Having said that, I have just noticed that there is a discrepancy between the way C51 and uVision handle adjacent comments.

    C51 regards the following as 2 separate comments, but uVision only colours the bold bit as a comment:

    /* Comment 1 *//* Comment 2
                     Comment 2 cont'd */
    

    It appears that uVision has taken the "//" as a C++ Style comment, without "realising" that it's actually the C-Style "*/" and "/*" comment delimiters "back-to-back"