poor names for volatile, noalias, const

Kevin Braunsdorf ksb at j.cc.purdue.edu
Tue Apr 5 08:11:39 AEST 1988


What I'm going to try to explain here is what *I think* the ANSI C group
is trying to provide via "const" "volatile" "noalias", and a better
model that I use.

First I will explain *my* model: what I want to do here is define a set
of type qualifiers that work in theory to specify all the things an
optimizer needs to know to optimize a language like C.

The three main type qualifiers are:
	exclusive	ordinary	volatile

which may be further qualified by:
	null		read		write		rmw

{yeah, I know `read' and `write' are important UNIX system calls...
 just for the sake of argument keep reading, and put down the soap box :-)}

I define them thus:

A type qualifier on a type tells the compiler something about how
the current context should treat the data that is of that type.  It
may also imply how other contexts may be (possibly concurrently)
accessing the same data.  It may imply that no other context can be
accessing the data.

A type qualifier "exclusive" tells the compiler that the current
context is the *only* context that can access the data at hand.  In
addition, it further promises that this data is only accessible through
the "exclusive" qualified name {path}.

A type qualifier of "ordinary" tells the compiler that the current
context has all active names for the data, and that they all have the
same unqualified type.  No other context may read or write to this data
while this context has control (relinquish control only with data synced).

A type qualifier of "volatile" tells the compiler that the current
context is *not* the only context that can see this data, some other
context may have a name for this data, or there may be another name for
this data in this context that may have another (unrelated) type.

Any type qualifier may be followed by an access limiter:

Access of "null": this data may not be read or written, but its address may be
used in address computation.

Access of "read": this data may only be read.

Access of "write": this data may only be written.

Access of "rmw": this data may be read, or written.

The default access limiter is "rmw".

Thus
	ANSI			mine
	----			----
	const			ordinary read
	noalias			exclusive [rmw]
	noalias const		exclusive read
	volatile		volatile [rmw]
	volatile const		volatile read

Now, how may data move around?  I won't insult your intelligence with the
rules for access limiters: you cannot assign to something limited for
read only....

But assuming you pass the access limiter constraint the rest of the
type qualifier can safely be ignored for simple data movement:

	exclusive int ei;
	volatile int vi;
	ordinary int oi;

	ei = vi = oi;		/* all OK.				*/

The only rules we need to look at now are the rules for creating and
asigning pointers to qualified types:

There are only nine legal combinations:

- a pointer to an exclusive {type} may be passed as a parameter, or
  assigned by initialization to a pointer to an exclusive {type}.

- a pointer to an ordinary {type} may be passed as a parameter, or
  assigned by initialization, or assigned via the assignment operator
  to a pointer to an ordinary {type}.

- a pointer to an ordinary {type} may be passed as a parameter, or
  assigned by initialization, or assigned via the assignment operator
  to a pointer to a volatile {type}.

- a pointer to an volatile {type} may be passed as a parameter, or
  assigned by initialization, or assigned via the assignment operator
  to a pointer to a volatile {type}.

- a pointer to a rmw limited {type} may be passed as a parameter, or
  assigned by initialization, or assigned via the assignment operator
  to a pointer to a read limited {type}.

- a pointer to a rmw limited {type} may be passed as a parameter, or
  assigned by initialization, or assigned via the assignment operator
  to a pointer to a write limited {type}.

- a pointer to a rmw, read, or write limited {type} may be passed
  as a parameter, or assigned by initialization, or assigned via the
  assignment operator to a pointer to a null limited {type}.

No other pointer combinations are legal.  Attempts to remove access
limitations or change qualifications on object should result in stern
admonishments from the compiler.

{ Note that all constants should be "ordinary read" by default... }

It is obvious from these rules that one needs to be able to specify the
access limiter and type qualifier on any constant: otherwise it is not
possible to initialize a pointer to an exclusive int... or a pointer to
a rmw int (so what else is new in C: one can't do that now).

....

There is much more to talk about WRT this topic: let me simply state
that the ANSI solution doesn't address all the issues involved in
this complex topic.

	- does exclusive apply if I move the pointer? warning?
	- does a volatile pointer imply volatile indirection?
	- how much optimization does this allow that I couldn't do anyway?
	- how hard to implement?
	- maintain this kind of code?
	- ~90% programming, or ~50% programming?
	- why are we bothering?

If anyone is interested enough in more discussion of this we should do
it via mail, Please.

Thanks for all you time:
Kevin Braunsdorf		pur-ee!ksb	or ksb at j.cc.purdue.edu
K Project			pur-ee!gawk!klang



More information about the Comp.lang.c mailing list