[comp.lang.c] Pragma and noalias

bill@proxftl.UUCP (T. William Wells) (06/28/88)

Recently, there was a posting suggesting that #pragma could be
used to tell the compiler of aliasing. Now, I am not advocating
this use, but one respondent commented that #pragma could not be
used for this purpose because it changed the semantics of the
language.

I looked up the #pragma in the standard, and all it says is that
the #pragma causes the compiler to behave in an implementation
defined manner. Now, while one could argue about just what
"implementation defined" means, I'd like to point out that using
#pragma for this purpose can't (in a correct program) be argued
against by any interpretation of "implementation defined".

My reasoning is this: in a correct program, where the #pragma
would be used, the variables referred to are IN FACT not
aliased. This means that the #pragma has NO effect on the
results of the program. However you interpret "implementation
defined", surely this falls under that heading!

The counter argument that in an incorrect program the #pragma
changes the semantics of the program in a manner which does not
have to be consistent with any kind of "implementation defined"
does not interest me: I would put optimization #pragmas only in
programs that work correctly; that is just good programming
practice. Thus, for me, this argument boils down to "the #pragma
is bad because a bad programmer will misuse it", among C
programmers, surely this particular argument is irrelevant!

gwyn@brl-smoke.ARPA (Doug Gwyn ) (06/28/88)

In article <381@proxftl.UUCP> bill@proxftl.UUCP (T. William Wells) writes:
>My reasoning is this: in a correct program, where the #pragma
>would be used, the variables referred to are IN FACT not
>aliased. This means that the #pragma has NO effect on the
>results of the program.

Nice try, but no cigar.  "Correct program" is logically prior to
consideration of the effect of #pragma.  The intention, I believe,
was to specify that an arbitrary #pragma-free correct program could
have an arbitrary #pragma inserted at an arbitrary (line boundary)
point and would still be a correct program.  This doesn't fit what
you're trying to do.

I have finally been convinced that whether or not #pragma is really
allowed to affect the semantics of a correct program has not been
clearly specified.  Unless this is remedied, the only safe thing to
do with #pragma will be to not use it.