Error recovery (long)
Walter Bright
bright at dataioDataio.UUCP
Fri May 30 03:15:51 AEST 1986
In article <312 at uw-nsr.UUCP> john at uw-nsr.UUCP (John Sambrook) writes:
>While on the subject of compilers, I would like to share two other features
>of this compiler that I find useful.
>The second feature is the ability to declare certain data structures as
>"read only." This is done via a compiler switch "-R" and applies to all
>data structures that are initialized to a constant value within the
>compilation unit.
>
> int a = 1; /* "read only" */
> main() {
> int b; /* "read / write" */
>
> b = a; /* this is legal */
> a = 2; /* this is not */
> }
The declaration for a can be made 'read only' by declaring it as follows:
const int a = 1;
Doing an assignment to a will then cause a syntax error when compiling.
This is in the draft ANSI C spec.
More information about the Comp.lang.c
mailing list