dan@rna.UUCP (Dan Ts'o) (03/19/89)
I'm sure this must have been covered before, but I haven't seen it myself... I am writing a (large) C program that runs under both UNIX and MSDOS. I am using the Microsoft 5.0 C compiler for MSDOS and 4.3BSD's CC for VAX UNIX. There is a portion of code that only is relevant under MSDOS. It is surrounded by #ifdef MSDOS -> #endif. Within that code, I use MSC's #pragma loop_opt(off) to suppress the loop optimization of a (volatile) device register. The 4.3BSD complains about the #pragma, even though it should be excluded entirely since the #ifdef MSDOS is not satisfied: #ifdef MSDOS ... C code ... #pragma loop_opt(off) while(...) ... #endif I naturally see how this could happen, although I do consider it a bug (what does ANSI say about this sort of thing). Is there any way around this ? (I know I could write the C code such that the #pragma isn't necessary... that's not an answer). Please email responses. Thanks. Cheers, Dan Ts'o 212-570-7671 Dept. Neurobiology dan@rna.rockefeller.edu Rockefeller Univ. ...cmcl2!rna!dan 1230 York Ave. rna!dan@nyu.edu NY, NY 10021 tso@rockefeller.arpa tso@rockvax.bitnet
egisin@mks.UUCP (Eric Gisin) (03/21/89)
A kludgy solution that will work with many pre-ANSI compilers is to indent any ANSI preprocessor directives so that the old compiler will ignore them. This works with Greenhill C on BSD: #if 0 #pragma x #endif
henry@utzoo.uucp (Henry Spencer) (03/21/89)
[I am disregarding Dan's request to reply by mail, as I think it is of general interest and hasn't really been covered before.] In article <435@rna.UUCP> dan@rna.UUCP (Dan Ts'o) writes: > ... The 4.3BSD complains about the #pragma, even though it should be >excluded entirely since the #ifdef MSDOS is not satisfied: > >#ifdef MSDOS > ... C code ... >#pragma loop_opt(off) > while(...) > ... >#endif > > I naturally see how this could happen, although I do consider it a >bug (what does ANSI say about this sort of thing). Is there any way around >this ? ... As I read the fine print in the Oct. draft, an unrecognized thing that looks like a directive, in a section that is being skipped, is not in fact a directive and therefore should not draw a complaint, except perhaps a warning message from an excessively-clever compiler. An ANSI-compatible compiler will ignore a #pragma in that position (well, probably... the old "can #pragma change the rules?" question can make trouble here). As to how to get around it, try putting white space in front of the # that starts the #pragma. An ANSI-compatible compiler will recognize it even so, and with luck your MeSsDOS compiler will too, but the old compilers won't see it unless the # is first on the line. -- Welcome to Mars! Your | Henry Spencer at U of Toronto Zoology passport and visa, comrade? | uunet!attcan!utzoo!henry henry@zoo.toronto.edu
dan@rna.UUCP (Dan Ts'o) (03/22/89)
In article <1989Mar20.190946.23190@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: )In article <435@rna.UUCP> dan@rna.UUCP (Dan Ts'o) writes: )) ... The 4.3BSD complains about the #pragma, even though it should be ))excluded entirely since the #ifdef MSDOS is not satisfied: )) ))#ifdef MSDOS )) ... C code ... ))#pragma loop_opt(off) )) while(...) )) ... ))#endif )) )As I read the fine print in the Oct. draft, an unrecognized thing that )looks like a directive, in a section that is being skipped, is not in )fact a directive and therefore should not draw a complaint, except perhaps )a warning message from an excessively-clever compiler. ) )As to how to get around it, try putting white space in front of the # )that starts the #pragma. An ANSI-compatible compiler will recognize )it even so, and with luck your MeSsDOS compiler will too, but the old )compilers won't see it unless the # is first on the line. Thanks to everyone that responded. As far as the "4.3BSD complains", I should have been more specific: The original 4.3BSD VAX C compiler not only complains, it gives up entirely. I haven't tried the 4.3BSD Tahoe compiler. As far as how to get around it, Henry's suggestion, which a couple of others also offered, though kludgy, was the most satisfactory -- and it works. That is, simply putting white space in front of the #pragma cause the 4.3BSD C compiler to ignore it (that is, the pre-processor doesn't realize that it should interpret the #pragma). ...Which reminds me... Remember the days when the pre-processor wasn't even invoked unless the first CHARACTER of the C source file was #. The good ol' daze...