When do you use const
Dan Bernstein
brnstnd at kramden.acf.nyu.edu
Sat Feb 2 03:51:58 AEST 1991
In article <1991Feb1.203935.18927 at csrd.uiuc.edu> bliss at sp64.csrd.uiuc.edu (Brian Bliss) writes:
> func f (const int *x, int *y);
> then once the comipler fetches the value of *x, it need not fetch
> it again in the subroutine, means it is constant. if it were not
> constant, then we could potentially modify the value of *x by
> assigning through *y (if x == y), and the compiler would need to
> recalculate *x every time it was needed (if *y or any global variable
> has been modified since the last calculation of *x).
Wait a minute. I thought const was only a prohibitive qualifier (you
can't set *x = foo) rather than an assertive qualifier (*x won't
change while it's in scope). Aren't you allowed to call f(&z,&z) upon an
int z (assuming prototypes are in scope), and doesn't f() have to reload
*x every time?
---Dan
More information about the Comp.lang.c
mailing list