Another sizeof question

Shankar Unni shankar at hpclscu.HP.COM
Tue Nov 20 12:43:03 AEST 1990


Doug Gwyn writes in response to a note from Norman Diamond:

> In article <3928 at male.EBay.Sun.COM> diamond at tkou02.enet.dec.com (diamond at tkovoa) writes:
> >If this is really true, it defeats the purpose of #pragma.  My understanding
> >was that #pragma may have any implementation-defined effect WHICH does not
> >change the meaning of a conforming program (though it may change the effect
> >of a nonconforming program).  That definition would have been far more useful.
> 
> That was my argument, but when Walter Murray requested a formal ruling on
> this, even I had to agree that the wording in the C standard leads to the
> conclusion that a strictly conforming program cannot use #pragma.

And that is as it should be.

Consider for a moment if the ANSI committee had adopted something like
Norman's interpretation: a program must behave the "same" way (whatever
that is - leave it for the moment) with or without the #pragma. Where would
that leave, just to take an example, "#pragma ALIGN <something>"?

Often, such alignment pragmas are required to help programs read binary
struct images from other machines. Programs which depend on such pragmas
are, of course, totally non-conforming.

But if you forbid a pragma from ever having a non-behavior-modifying
effect, you cannot even implement such a pragma for non-conforming programs
(because that would make the compiler non-conforming, even though it is
hard to test for such a situation with any kind of a verification suite).

If you choose some other method of specifying it (say, "#align <xx>"),
that also must be diagnosed by a conforming compiler implementation.

Result: you cannot implement such a mechanism in a conforming compiler 
*at all*.

Thus the only reasonable approach is to say that a "#pragma" can change the
behavior of a program in really unspecified ways (unless you want to get
into the business of standardizing specific pragmas, like Ada does).
-----
Shankar Unni                                   E-Mail: 
Hewlett-Packard California Language Lab.     Internet: shankar at hpda.hp.com
Phone : (408) 447-5797                           UUCP: ...!hplabs!hpda!shankar



More information about the Comp.std.c mailing list