Topic: `const' and `volatile' are not type specifiers
Author: gb@cs.purdue.EDU (Gerald Baumgartner)
Date: 21 Oct 92 02:24:01 GMT Raw View
What is the semantics of
struct c {
const int foo (void);
};
Is it a class with a public member function returning a constant integer?
I did not find anything in the ARM explaining what a `const' return
type means. GCC 2.2.2 throws the information about this `const' away
without printing any message. In case of file-level functions, GCC
records the const-ness in the function type node (instead of the
return type node). I did not find out yet, what's the effect of that,
either. The same goes for `volatile'.
In my opinion, both `const' and `volatile' don't make sense as type
specifiers. Semantically, a type is a set of values (each of which is
a constant). It is meaningless to call some of those values `const',
some `volatile', some neither, some both.
I think, `const' and `volatile' should be called location specifiers.
That is, they should be associated with variables, parameters, and
locations pointed to by pointers. This way, the type system becomes
easier to understand, subtyping rules become clearer, and the above
question wouldn't arise.
--Gerald
--
Gerald Baumgartner
Dept. of Computer Sciences, Purdue University, W. Lafayette, IN 47907
Internet: gb@cs.purdue.edu, UUCP: ...!{decwrl,gatech,ucbvax}!purdue!gb
Author: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
Date: Thu, 22 Oct 1992 07:34:03 GMT Raw View
gb@cs.purdue.EDU (Gerald Baumgartner) writes:
>What is the semantics of
>
> struct c {
> const int foo (void);
> };
>
>Is it a class with a public member function returning a constant integer?
>
>I did not find anything in the ARM explaining what a `const' return
>type means. GCC 2.2.2 throws the information about this `const' away
>without printing any message. In case of file-level functions, GCC
>records the const-ness in the function type node (instead of the
>return type node). I did not find out yet, what's the effect of that,
>either. The same goes for `volatile'.
Gcc overloads the keyword "const" when used for a function return type
to mean that the function has no side-effects. This can be used for
functions like sin() and pow() to help improve the compiler's optimization.
Gcc overloads the keyword "virtual" when used for a function return type
to mean that the function never returns. This can be used for functions
like exit() and abort() to avoid spurious warnings like "function does
not return a value"; this is similar to using /* NOTREACHED */
comments to suppress warnings from lint.
--
Fergus Henderson fjh@munta.cs.mu.OZ.AU
This .signature virus is a self-referential statement that is true - but
you will only be able to consistently believe it if you copy it to your own
.signature file!
Author: zoo@cygnus.com (david d 'zoo' zuhn)
Date: Thu, 22 Oct 1992 11:23:19 GMT Raw View
Gcc overloads the keyword "virtual" when used for a function return type
to mean that the function never returns. This can be used for functions
like exit() and abort() to avoid spurious warnings like "function does
not return a value"; this is similar to using /* NOTREACHED */
comments to suppress warnings from lint.
This isn't quite true. The keyword used for this sort of function return
type is 'volatile' not 'virtual`. Other than that, everything above should
be just fine.
david d 'zoo' zuhn | There is great disorder under the heavens,
cygnus support | and the situation is excellent.
zoo@cygnus.com |