#pragma does only half the job (was Re: Pragma and noalias)

T. William Wells bill at proxftl.UUCP
Tue Jul 5 14:21:22 AEST 1988


In article <8176 at brl-smoke.ARPA>, gwyn at brl-smoke.ARPA (Doug Gwyn ) writes:
> In article <381 at proxftl.UUCP> bill at 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.

I just spent 20 seconds reading what the (second draft) standard
had to say about #pragma. In two words: NOT ENOUGH. All the
standard says is that adding one causes the implementation to
behave in an implementation defined manner. AND THAT IS ALL.
That does prohibit a #pragma from giving additional information
about the program. Let me repeat that:

	A PRAGMA CAN NOT GIVE INFORMATION ABOUT THE PROGRAM THAT
	THE COMPILER CAN'T FIGURE OUT FOR ITSELF.

Let me add: DAMN.

About the only kinds of things that I can see the current
#pragma being used for is to do things like

	#pragma fortran-callable        (arrange that fortran pgms can call)
	#pragma int*4                   (integers are 4 bytes)
	#pragma wchar_t short           (wide characters are shorts)
	#pragma base_reg a4             (specifies addressing off register a4)

and other things which have to do with the implementation.  This
is useful but is only half of what we need.

The standard should have, either as an extension to #pragma or
as another preprocessing statement, something like:

"If the #pragma asserts that X is a property of the program and
X is in fact a property of the program, a correct program shall
still be correct when the #pragma is added."

This would mean that writing strcpy as:

	char *
	strcpy(p1, p2)
	char    *p1;
	char    *p2;
	#pragma noalias p1[],p2[];
	{
		...
	}

is ok, because, given that the assertion (that p1 and p2 are not
aliased) is true, should the compiler make that assumption, the
program will be still correct.

An additional benefit is that the compiler could add run time
checks to verify the condition; this would not be an improper use
of the construct, for as long as the condition were true, there
would be no effect on the program.



More information about the Comp.lang.c mailing list