Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000436OCamlCamlIDLpublic2001-07-14 17:522001-07-30 16:28
Reporteradministrator 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000436: camlidl's preprocessor
DescriptionFull_Name: Dmitry Bely
Version: camlidl current cvs
OS: Windows NT 4.0
Submission from: d041.p3.col.ru (195.210.132.41)


test/unix.idl from camlidl distribution contains the following:

[---cut---]
quote(C,"
  #include <stdlib.h>
  #include <stdio.h>
  #include <sys/types.h>
  #include <sys/wait.h>
  #include <dirent.h>
  #include <unistd.h>
  #include <sys/stat.h>
  #include <sys/time.h>
  #include <fcntl.h>
...
")
[---cut---]

these #include statements are interpreted by an external preprocessor, which
camlidl calls during .idl compilation and became expanded in the resulting .c
file. Obviously that's not what the programmer expected.

Ideal solution would be to ignore preprocessor directives inside qoute
statement, but I realize that it's almost impossible to implement for external
preprocessor. So at least do not use above (wrong) construct in your examples --
it should be written as

[---cut---]
quote(C,"#include <stdlib.h>")
quote(C,"#include <stdio.h>")
quote(C,"#include <sys/types.h>")
quote(C,"#include <sys/wait.h>")
quote(C,"#include <dirent.h>")
quote(C,"#include <unistd.h>")
quote(C,"#include <sys/stat.h>")
quote(C,"#include <sys/time.h>")
quote(C,"#include <fcntl.h>")
...
")
[---cut---]

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0000061)
administrator (administrator)
2001-07-20 15:53

> test/unix.idl from camlidl distribution contains the following:
>
> [---cut---]
> quote(C,"
> #include <stdlib.h>
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/wait.h>
> #include <dirent.h>
> #include <unistd.h>
> #include <sys/stat.h>
> #include <sys/time.h>
> #include <fcntl.h>
> ...
> ")
> [---cut---]
>
> these #include statements are interpreted by an external preprocessor, which
> camlidl calls during .idl compilation and became expanded in the resulting .c
> file. Obviously that's not what the programmer expected.

I was under the impression that # directives inside a string literal
must be ignored by an ANSI C preprocessor; this is what gcc does,
however the K&R second edition doesn't seem to guarantee this.

So at least do not use above (wrong) construct in your examples --
> it should be written as
>
> [---cut---]
> quote(C,"#include <stdlib.h>")

Sounds very reasonable. I'll do that.

Best regards,

- Xavier Leroy

(0000062)
administrator (administrator)
2001-07-20 19:20

Xavier Leroy <Xavier.Leroy@inria.fr> writes:

> > test/unix.idl from camlidl distribution contains the following:
> >
> > [---cut---]
> > quote(C,"
> > #include <stdlib.h>
> > #include <stdio.h>
> > #include <sys/types.h>
> > #include <sys/wait.h>
> > #include <dirent.h>
> > #include <unistd.h>
> > #include <sys/stat.h>
> > #include <sys/time.h>
> > #include <fcntl.h>
> > ...
> > ")
> > [---cut---]
> >
> > these #include statements are interpreted by an external preprocessor, which
> > camlidl calls during .idl compilation and became expanded in the resulting .c
> > file. Obviously that's not what the programmer expected.
>
> I was under the impression that # directives inside a string literal
> must be ignored by an ANSI C preprocessor; this is what gcc does,
> however the K&R second edition doesn't seem to guarantee this.

Yes, gcc ignores preprocessor directives inside string literals, but msvc
expands them even in ANSI compatibility mode:

[test.c]
"
#define A B
"
A
[end of test.c]

D:\Work\camlidl-test>cpp test.c
# 1 "test.c"
"
#define A B
"
A

D:\Work\camlidl-test>cl /nologo /E /Za test.c
test.c
#line 1 "test.c"
"

"
B

Probably that's MSVC bug, because ISO C++ standard (don't have an ANSI C
one here) tells that

[---cut---]
2- A preprocessing token is the minimal lexical element of the language in
translation phases 3 through 6. The categories of preprocessing token are:
header names, identifiers, preprocessing numbers, character literals,
string literals, preprocessing-op-or-punc, and single non-white-space
characters that do not lexically match the other preprocessing token
categories.
...
1- A preprocessing directive consists of a sequence of preprocessing
tokens. The first token in the sequence is a # preprocessing token that is
either the first character in the source file (optionally after white space
containing no new-line characters) or that follows white space containing
at least one new-line character. The last token in the sequence is the
first new-line character that follows the first token in the sequence.*
[---cut---]

But anyway it's easier to work around this bug when wait until MS fix it
:-)

Hope to hear from you soon,
Dmitry


(0000063)
administrator (administrator)
2001-07-30 16:28

Fixed example as suggested. XL, 2001-07-30

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker