Type modifiers in C

Dick Dunn rcd at opus.UUCP
Wed Oct 30 17:00:06 AEST 1985


> In considering some new type modifiers that are useful for multiprocessing
> one needs to consider how type modifiers fit in the ANSI standard.
> Could someone explain all the details of what you might do with for example
> the volatile type modifier...

...examples follow of various combinations of types and "volatile" at
various points.

I don't have the standard proposal to examine, but there's a general point
about these "type modifiers"--seemingly a generalization of what are more
commonly [mis?]named "storage classes".  There are attributes of objects
which affect the declaration of the object itself but which don't carry
outward, and there are other attributes which have to be propagated to
referencing or containing objects.

Attributes like C's "static" (in the sense that it means "local") and
"external" are used to establish some property of an object at its
declaration, but they don't need to be propagated through, say, a pointer
to the object.  (A pointer to a local int need not be different from a
pointer to a global int.)

Attributes like "constant" or "volatile" need to be propagated through
dependent types.  (A pointer to a volatile int is different from a pointer
to a "normal" int, in the sense that the pointers point to objects which
have different properties; if you dereference the pointers, you have to
treat the resulting objects differently.)

In "current" C (as in K&R), the "static" attribute is particularly
unfortunate in this regard:  When applied to a procedure or a variable
outside of a procedure, it restricts the scope of the object only and there
is no need to propagate the attribute.  When applied to a variable within a
procedure, it affects the semantics and the extent of the variable; in some
sense the static-vs-automatic distinction should be propagated.  (In some
languages it would be prohibited to assign the address of an automatic
variable to a more global pointer--i.e., a pointer whose extent exceeds
that of the variable.)
-- 
Dick Dunn	{hao,ucbvax,allegra}!nbires!rcd		(303)444-5710 x3086
   ...At last it's the real thing...or close enough to pretend.



More information about the Comp.lang.c mailing list