www.digitalmars.com         C & C++   DMDScript  

c++ - C style comments cause problem

reply SSingh <SSingh_member pathlink.com> writes:
While trying to make one of my old programs ANSI-C compatible, especially the
comments, I came across a problem. I have reduced the problem code to a few
lines. The compiler barfs on the following comments in the source code:

#include <stdio.h>

/* db 6 dup (0) == 00 00 00 00 00 00 */
int main()
{
printf("Hello world.\n");
return 0;
}

C:\DEV>sc sctest.c
sctest.c(9) : Lexical error: end of file found before end of comment, line 1
Fatal error: premature end of source file
--- errorlevel 1


I get this same error message from SC 6.1, SC 7.22, and DMC 8.40

I tried several compilers from Borland, MicroSoft, Watcom, LCC etc., and all of
them compile/run this code OK.

Is it something wrong with the source or is it due to the SC/DMC compiler?
Jan 19 2005
parent reply "Walter" <newshound digitalmars.com> writes:
I can't reproduce the error with the example given.

Is it possible you have an embedded zero or ^Z (0x1A) character inside the
comment?

"SSingh" <SSingh_member pathlink.com> wrote in message
news:csmiun$emo$1 digitaldaemon.com...
 While trying to make one of my old programs ANSI-C compatible, especially

 comments, I came across a problem. I have reduced the problem code to a

 lines. The compiler barfs on the following comments in the source code:

 #include <stdio.h>

 /* db 6 dup (0) == 00 00 00 00 00 00 */
 int main()
 {
 printf("Hello world.\n");
 return 0;
 }

 C:\DEV>sc sctest.c
 sctest.c(9) : Lexical error: end of file found before end of comment, line

 Fatal error: premature end of source file
 --- errorlevel 1


 I get this same error message from SC 6.1, SC 7.22, and DMC 8.40

 I tried several compilers from Borland, MicroSoft, Watcom, LCC etc., and

 them compile/run this code OK.

 Is it something wrong with the source or is it due to the SC/DMC compiler?

Jan 19 2005
parent reply SSingh <SSingh_member pathlink.com> writes:
In article <csn5bk$157d$4 digitaldaemon.com>, Walter says...
I can't reproduce the error with the example given.

Is it possible you have an embedded zero or ^Z (0x1A) character inside the
comment?

Yes, there was an embedded zero inside the comment, it only became apparent when the text was viewed as hex values. But I wonder why the other compilers never detected this? Thanks for the hint and a quick reply. If I am not mistaken then you must be Walter Bright, and I am a fan of your compilers. Let me also take this opportunity to thank and compliment you on the fine line of compilers that you have developed. I own SC6.1 SC7.0 SC7.2 SC7.5 and I have also tried the new DMC8.40. I also have compilers from Borland, MicroSoft, and Watcom, but when compared to these your compilers could only be described as "Greased Lightning." I have been to your Home page and greatly enjoyed the "Trip Around the World Charles Taylor Bright travels around the world at the turn of the century." Thanks, keep up the good work, I hope the Language D also makes it big. -SSingh
Jan 20 2005
parent "Walter" <newshound digitalmars.com> writes:
"SSingh" <SSingh_member pathlink.com> wrote in message
news:csohr3$2vr5$1 digitaldaemon.com...
 In article <csn5bk$157d$4 digitaldaemon.com>, Walter says...
Is it possible you have an embedded zero or ^Z (0x1A) character inside


comment?


 the text was viewed as hex values. But I wonder why the other compilers

 detected this?

DMC uses the 0 or ^Z as an "end of file" sentinel. Some early text editors would mark end of file this way, with random garbage appearing after it.
 Thanks for the hint and a quick reply.

 If I am not mistaken then you must be Walter Bright, and I am a fan of

 compilers.

 Let me also take this opportunity to thank and compliment you on the fine

 of compilers that you have developed. I own SC6.1 SC7.0 SC7.2 SC7.5 and I

 also tried the new DMC8.40. I also have compilers from Borland, MicroSoft,

 Watcom, but when compared to these your compilers could only be described

 "Greased Lightning."

Thanks!
 I have been to your Home page and greatly enjoyed the "Trip Around the

 Charles Taylor Bright travels around the world at the turn of the

Unfortunately, he died before I was born. I would really have liked to know him. I have to be satisfied with the letters and family stories about him.
 Thanks, keep up the good work, I hope the Language D also makes it big.
 -SSingh

Jan 20 2005