#pragma

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Jan 19 08:35:39 AEST 1989


In article <12570002 at hpclwjm.HP.COM> walter at hpclwjm.HP.COM (Walter Murray) writes:
>I'm in the same boat.  Maybe it's time for someone to post a summary/update
>on the #pragma question.

There isn't much to tell.  #pragma is constrained by the Standard
only insofar as it must pass through the preprocessing grammar.
I believe several vendors are interested in establishing some
additional agreement about how to format #pragma and in setting
up some way of registering pragmas in order to avoid conflict
among vendors.  Such agreements will not be part of the ANSI C
standard, however.  There may be a special interest group working
on this; I don't know.

>1.  A #pragma causes an implementation to behave in an implementation-defined
>    manner.  Could that include, for example, following unsigned-preserving
>    promotion rules, or must the behavior still be ANSI?

A non-conforming implementation can do whatever it pleases.

A conforming implementation must follow ALL the rules in the
Standard; permitting implementation-defined behavior in specific
circumstances is not to be interpreted as granting license to
ignore other relevant specifications.

>2.  A strictly conforming program shall not produce output dependent on
>    any implementation-defined behavior.  Does it follow that a strictly
>    conforming program shall not use a #pragma?

Only if it affects the output of the program...  We actually wanted
to say that its "meaning" doesn't depend on any unspecified,
undefined, or implementation-defined behavior, but "output" was
the best we could come up with in pure standards language.

In practice, there is NO portable use of #pragma.  A program's output
conceivably MIGHT depend on SOME implementation's handling of a #pragma;
therefore #pragma ought not to be used in a strictly conforming program
(i.e. one intended specifically to be maximally portable).

Really, #pragma is intended to give advice to the compiler such as:
	produce a listing
	optimize this block in a certain way
	assign this data to a certain kind of storage
It can undoubtedly be made to do many other things, not all of them
advisable.



More information about the Comp.std.c mailing list