[comp.lang.c] Pragms

pardo@uw-june.UUCP (David Keppel) (12/23/87)

ok@quintus.UUCP (Richard A. O'Keefe) wrote:
|(3) A snag with things like volatile and noalias is that they
|clutter up the language.  There are a great many things that one
|might want to tell a compiler.  There should be one generic
|mechanism for all of them.  The simplest scheme I can think of
|is to replace the rule
|
|	type_qualifier : CONST | VOLATILE ;
|
|by	type_qualifier : CONST | PRAGMA '(' praginfo ')' ;
|
|	praginfo : /* empty */ | praginfo primary_expr ;
|
|so that one could declare
|
|	extern pragma(volatile)	struct device tty_device;
|
|or whatever.  The definition of 'praginfo' was carefully designed so that
|	#define pragma(x)
|could be used in a compiler which didn't yet understand pragma(),
|but in general a compiler would accept some pragmas and warn about
|the others.  This approach takes one reserved word in the language,
|but imposes no bound on the number of hints you can give the compiler.


Robf Fair ihnp4!pyuxww!pyuxf!robf2 writes [paraphrasing]
>MSC 5.0 has exactly these kind of pragmas/command line options,
>and they affect ALL variables within the selected range, while the ``noalias''
>keyword allows much finer control of exactly which variables have aliases:
>
>#pragma noalias(on)
>func()
>{
>	char	*c;
>	char	*d;
>	,,,
>}
>#pragma noalias(off)

Not quite the same.  What Richard is proposing is that the pragma can be
also in a form different from what the MSC compiler allows, so if you only
want "c" to be noalias, you can say something like:

	pragma(noalias) char	*c;
	char			*d;

>It seems that this has some serious problems in implementation,
>for example how far should the aliasing information be rememebered,
>(single function, rest of the source file etc)
>and how should variables redefined in nested scope be handled ?

If I understand your question you are worried about a inner scope
variable getting a pragma from an outer scope declaration.  No problem.
Work it the same way that "noalias" or "register" is done; it is stuck in
the compilers' symbol table and is accessable anytime that the symbol is
visible:

static int *splodge;

foo()
{
    pragma(noalias) char	*splodge;

    { register struct fstab	*splodge;  ... }
}

In this case only the "splodge" in the outermost level of "foo()" is
noalias, as only the innermost "splodge" is register.

	;-D on  (Everything is just a hint anyway)  Pardo