Technical article 100839

I cannot use // style comments with the icc compiler.

OpenServer 5.0.0OpenServer 5.0.2

Written · Last revised

Problem

I have code that includes comments of the style:

// This is a comment

in my sources. The icc compiler does not understand this type of comment.

Cause

The icc compiler enforces strict ANSI and ISO c compliance and the

// This is a comment

style of comment is not compliant with these standards. The

// This is a comment

style of comment may result in valid c (ansi and k&r) code being compiled incorrectly. Do not use this style of comment in your c code.

Solution

A feature request has been filed to add support for the // style of comment in a future release of product.

Currently the only solution is to convert your source comments to the

/* This is a comment */
style of comment.

The filter program enclosed below can be used to do this.

/* Usage: a.out < test.c > test.out */
#include <stdio.h>
#define TRUE    1
#define FALSE   0
typedef char Boolean;

main(int argc, char *argv[]) { int c, d; Boolean Comment = FALSE;

while ((c = getchar()) != EOF)
{
        switch (c)
        {
        case '/':
                if ((d = getchar()) == EOF)
                {
                        putchar(c);
                        exit(0);
                }
        if (d == '/')
        {
                printf("/*");
                Comment = TRUE;
        }
        else
        {
                printf("%c%c", c, d);
        }
        break;
case '\n':
        if (Comment)
        {
                printf(" */");
                Comment = FALSE;
        }
        /* DROP THRO' */
default:
        putchar(c);
        break;
}
}
}

From the Xinuos technical article database, record 100839. Reproduced with permission. The original is at www.sco.com/ta/100839, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.