Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

_Pragma operator

0 views
Skip to first unread message

Neil Booth

unread,
Nov 12, 2000, 3:00:00 AM11/12/00
to
The C99 standard does not state where a _Pragma operator
may appear. Thus am I right in considering it OK to
appear in a preprocessor directive?

e.g.

#if 1 _Pragma("foo")
...
#endif

and stuff like

_Pragma("_Pragma(\"foo\")")

I have implemented these for GNU CPP, but don't know whether I
need have or not.

Do any other preprocessors implement _Pragma yet?

Thanks,

Neil.


Clive D.W. Feather

unread,
Nov 22, 2000, 3:00:00 AM11/22/00
to
In article <3A0EB276...@earthling.net>, Neil Booth
<ne...@earthling.net> writes

>The C99 standard does not state where a _Pragma operator
>may appear.

It may appear anywhere that doesn't violate the syntax or the
constraints (e.g. #if _Pragma ("foo") meets the syntax but not the
constraint requiring #if to take an integer constant expression).

--
Clive D.W. Feather | Internet Expert | Work: <cl...@demon.net>
Tel: +44 20 8371 1138 | Demon Internet | Home: <cl...@davros.org>
Fax: +44 20 8371 1037 | Thus plc | Web: <http://www.davros.org>
Written on my laptop; please observe the Reply-To address

Neil Booth

unread,
Nov 22, 2000, 3:00:00 AM11/22/00
to
Hi Clive,

"Clive D.W. Feather" wrote:

> It may appear anywhere that doesn't violate the syntax or the
> constraints (e.g. #if _Pragma ("foo") meets the syntax but not the
> constraint requiring #if to take an integer constant expression).

The problem I have with this explanation is that you've just
changed the meaning of the example quoted in the standard
where _Pragma is used in a #define statement.

In the end this dilemma - why should it have an effect in e.g. #if
but not #define, that led my to treat _Pragma as a normal token
within directives.

Neil.

Thomas Pornin

unread,
Nov 23, 2000, 3:00:00 AM11/23/00
to
According to Neil Booth <Ne...@REMOVETHIS.earthling.net>:

> In the end this dilemma - why should it have an effect in e.g. #if
> but not #define, that led my to treat _Pragma as a normal token
> within directives.

Another option is to treat _Pragma() as a special macro, which takes
one argument (which must be a string literal token) and is replaced by
nothing. It should be compatible with the standard, and that way, it is
perfectly clear why it might appear inside #if and not inside #define
directives: there is no macro substitution inside a #define.

The more I think about this scheme, the more elegant it seems to me. The
amount of code needed to handle this in the preprocessor is minimal,
since it uses standard macro invocation code.

I think I will just do that.


--Thomas Pornin

0 new messages