[comp.lang.c] Yet Another Argument for Nested Comments

scl@unislc.uucp (Sean Landis) (01/29/91)

These arguments always seem more compelling when they reveal our own errors!
I had a header file, hash.h, that looked like:

#ifndef HASH_H
#define HASH_H

... The code ...

#endif /* HASH_H


Then, I had hash.C:

/********************************************************************
*  My comment header.
*
********************************************************************/

... The code ...



And, finally, main.C:


main()
{
... the code ...

}

... some more functions ...


Well, I was seeing truely bizarre error messages at compile time.
Unfortunately, I was able to make them go away.  Since I am just getting
into C++, I allowed myself to believe that I was doing something wrong.
I finally got all the modules to compile, but I started getting crazy
messages from the linker stating that main() was an undefined  symbol.
Now you see it, now you don't.  Well, after using every tool I had to figure
it out, I confirmed that main was not in main.o.  It was getting late,
and I was desperate, so I moved main() to the end of main.C.  I got a
different link error - main() was fine!  Well, I was very gladdened because
now I had some evidence.  Unfortunately, war broke out and I decided to go
home, leaving the problem to the next day.

Working, afresh, I spotted the error quickly.  Here's hash.h again:


#ifndef HASH_H
#define HASH_H

... The code ...

#endif /* HASH_H


Looks like I forgot to terminate this comment.  When this was included in
hash.C, the comment header quietly terminated this comment without harm.
Unfortunately, (fortunately?), main.C was test code, and had no header.
So, I was left to baffle over the bizarre.

Now, if C and C++ supported nested comments, the compiler would have been
obliged to report that there was an unterminated comment.  I would have
saved about four hours of work!  Oh well.  It *NOW* seems to me that some
traditions are worth parting from :-)

Newsgroups: comp.lang.c
Subject: Yet Another Argument for Nested Comments
Distribution: local

These arguments always seem more compelling when they reveal our own errors!
I had a header file, hash.h, that looked like:

#ifndef HASH_H
#define HASH_H

... The code ...

#endif /* HASH_H


Then, I had hash.C:

/********************************************************************
*  My comment header.
*
********************************************************************/

... The code ...



And, finally, main.C:


main()
{
... the code ...

}

... some more functions ...


Well, I was seeing truely bizarre error messages at compile time.
Unfortunately, I was able to make them go away.  Since I am just getting
into C++, I allowed myself to believe that I was doing something wrong.
I finally got all the modules to compile, but I started getting crazy
messages from the linker stating that main() was an undefined  symbol.
Now you see it, now you don't.  Well, after using every tool I had to figure
it out, I confirmed that main was not in main.o.  It was getting late,
and I was desperate, so I moved main() to the end of main.C.  I got a
different link error - main() was fine!  Well, I was very gladdened because
now I had some evidence.  Unfortunately, war broke out and I decided to go
home, leaving the problem to the next day.

Working, afresh, I spotted the error quickly.  Here's hash.h again:


#ifndef HASH_H
#define HASH_H

... The code ...

#endif /* HASH_H


Looks like I forgot to terminate this comment.  When this was included in
hash.C, the comment header quietly terminated this comment without harm.
Unfortunately, (fortunately?), main.C was test code, and had no header.
So, I was left to baffle over the bizarre.

Now, if C and C++ supported nested comments, the compiler would have been
obliged to report that there was an unterminated comment.  I would have
saved about four hours of work!  Oh well.  It *NOW* seems to me that some
traditions are worth parting from :-)

Sean
Newsgroups: comp.lang.c
Subject: Yet Another Argument for Nested Comments
Distribution: local

These arguments always seem more compelling when they reveal our own errors!
I had a header file, hash.h, that looked like:

#ifndef HASH_H
#define HASH_H

... The code ...

#endif /* HASH_H


Then, I had hash.C:

/********************************************************************
*  My comment header.
*
********************************************************************/

... The code ...



And, finally, main.C:


main()
{
... the code ...

}

... some more functions ...


Well, I was seeing truely bizarre error messages at compile time.
Unfortunately, I was able to make them go away.  Since I am just getting
into C++, I allowed myself to believe that I was doing something wrong.
I finally got all the modules to compile, but I started getting crazy
messages from the linker stating that main() was an undefined  symbol.
Now you see it, now you don't.  Well, after using every tool I had to figure
it out, I confirmed that main was not in main.o.  It was getting late,
and I was desperate, so I moved main() to the end of main.C.  I got a
different link error - main() was fine!  Well, I was very gladdened because
now I had some evidence.  Unfortunately, war broke out and I decided to go
home, leaving the problem to the next day.

Working, afresh, I spotted the error quickly.  Here's hash.h again:


#ifndef HASH_H
#define HASH_H

... The code ...

#endif /* HASH_H


Looks like I forgot to terminate this comment.  When this was included in
hash.C, the comment header quietly terminated this comment without harm.
Unfortunately, (fortunately?), main.C was test code, and had no header.
So, I was left to baffle over the bizarre.

Now, if C and C++ supported nested comments, the compiler would have been
obliged to report that there was an unterminated comment.  I would have
saved about four hours of work!  Oh well.  It *NOW* seems to me that some
traditions are worth parting from :-)

Newsgroups: comp.lang.c
Subject: Yet Another Argument for Nested Comments
Distribution: local

These arguments always seem more compelling when they reveal our own errors!
I had a header file, hash.h, that looked like:

#ifndef HASH_H
#define HASH_H

... The code ...

#endif /* HASH_H


Then, I had hash.C:

/********************************************************************
*  My comment header.
*
********************************************************************/

... The code ...



And, finally, main.C:


main()
{
... the code ...

}

... some more functions ...


Well, I was seeing truely bizarre error messages at compile time.
Unfortunately, I was able to make them go away.  Since I am just getting
into C++, I allowed myself to believe that I was doing something wrong.
I finally got all the modules to compile, but I started getting crazy
messages from the linker stating that main() was an undefined  symbol.
Now you see it, now you don't.  Well, after using every tool I had to figure
it out, I confirmed that main was not in main.o.  It was getting late,
and I was desperate, so I moved main() to the end of main.C.  I got a
different link error - main() was fine!  Well, I was very gladdened because
now I had some evidence.  Unfortunately, war broke out and I decided to go
home, leaving the problem to the next day.

Working, afresh, I spotted the error quickly.  Here's hash.h again:


#ifndef HASH_H
#define HASH_H

... The code ...

#endif /* HASH_H


Looks like I forgot to terminate this comment.  When this was included in
hash.C, the comment header quietly terminated this comment without harm.
Unfortunately, (fortunately?), main.C was test code, and had no header.
So, I was left to baffle over the bizarre.

Now, if C and C++ supported nested comments, the compiler would have been
obliged to report that there was an unterminated comment.  I would have
saved about four hours of work!  Oh well.  It *NOW* seems to me that some
traditions are worth parting from :-)

Sean
Newsgroups: local.news
Subject: BASEBALL CARDS
Distribution: local

I am interested in buying, selling, or trading baseball cards with anyone.

Sean Landis
x 3988
1-649-9810

steve@taumet.com (Stephen Clamage) (01/30/91)

scl@unislc.uucp (Sean Landis) writes:

>I had a header file, hash.h, that looked like:

>#ifndef HASH_H
>#define HASH_H

>... The code ...

>#endif /* HASH_H

In this example, an ANSI-conforming compiler is obliged to report a
comment which is not terminated in the file in which it started.  A 
helpful compiler would indicate the line on which the comment began.
This would have shown you the error immediately upon the first compilation.

Even though standard C does not have nested comments, a compiler may warn
about something that looks like a nested comment.  (A compiler may warn
about anything at all, so long as it does not reject or misinterpret a
legal program.)
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com

chip@tct.uucp (Chip Salzenberg) (01/30/91)

... which is actually an argument for making the compiler produce
a warning when it encounters "/*" in a comment.
-- 
Chip Salzenberg at Teltronics/TCT     <chip@tct.uucp>, <uunet!pdn!tct!chip>
 "I want to mention that my opinions whether real or not are MY opinions."
             -- the inevitable William "Billy" Steinmetz

dave@tygra.UUCP (David Conrad) (02/01/91)

Well, Turbo C++ 1.00 behaved on the program:
 
/* unterminated comment
 
void main(void)
{
  puts("Hello, world!");
}
 
/* I wonder, will it compile? */
 
as follows:
In the normal mode it produced an `empty' object file and produced no
warnings or errors.  With nested comments turned on (tcc -C test) it
complained `Error test.c 3: Unexpected end of file in comment started
on line 1' and stopped the compile.
--
David Conrad
tygra!dave@uunet.uu.net
tygra!dave@sharkey.cc.umich.edu
-- 
=  CAT-TALK Conferencing Network, Computer Conferencing and File Archive  =
-  1-313-343-0800, 300/1200/2400/9600 baud, 8/N/1. New users use 'new'    - 
=  as a login id.  AVAILABLE VIA PC-PURSUIT!!! (City code "MIDET")        =
   E-MAIL Address: dave@DDMI.COM

scott@bbxsda.UUCP (Scott Amspoker) (02/06/91)

In article <1991Feb1.091225.28034@tygra.UUCP> dave@tygra.UUCP (David Conrad) writes:
>[about nested/unterminated comments...]

I always keep a quick and dirty C program handy to search source files
for apparently unterminated comments (or "nested" comments).  I did this
one day after spending hours looking for a bug created when an unterminated
comment swallowed up a line of code.  Since then it has saved my butt on
a couple of occasions.

-- 
Scott Amspoker                       | 
Basis International, Albuquerque, NM |     This space available
(505) 345-5232                       | 
unmvax.cs.unm.edu!bbx!bbxsda!scott   |

sanders@peyote.cactus.org (Tony Sanders) (02/07/91)

In article <1991Jan28.205309.2836@unislc.uucp> scl@unislc.uucp (Sean Landis) writes:
>These arguments always seem more compelling when they reveal our own errors!
>I had a header file, hash.h, that looked like:
With nested comments you have the same type of problem.
What if you nested comments when you didn't mean to.

Better to just look for the obvious before spending 4 hours looking
for a compiler bug or somesuch.  I've done the same thing over
various problems.

Once I spent several hours of my time trying to find out why something
like this didn't work:

    system("stty raw");		/* only I didn't use system */
    /* much simplified of course */
    read(0,s,1);
    s[1] = '\0';
    fprintf(stderr,"debug: why isn't %s working\n",s);
    switch(s[0]) {
      case 'a':
	dothis();
	break;
      case 'b':
	dothat();
	break;
    }

First I was working from home... It worked just fine.

When I got to work, the 'a' worked ok but the 'b' was broken.
(actually it was like 'g' and 'o' and 'q' worked but 'z' and 'w' didn't
 or somesuch)  but the printf worked just fine.

After a couple of hours debug time I went into the other office to ask
a friend of mine to look at it and it was the other way around!!!
Different commands were broken.  Now what had I done.

My problem was I was looking for a bug in the compiler or the
IOP or the tty driver or something.

After debugging the .s file with another friend we finally fixed the
problem:   *s = *s & 0x7f;

-- sanders@peyote.cactus.org
First rule of software:  Throw the first one away.
and so on...