Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!rpi!uupsi!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.c Subject: Re: When do you use const Message-ID: <2571:Feb116:51:5891@kramden.acf.nyu.edu> Date: 1 Feb 91 16:51:58 GMT References: <1220@tredysvr.Tredydev.Unisys.COM> <1991Feb1.203935.18927@csrd.uiuc.edu> Organization: IR Lines: 16 In article <1991Feb1.203935.18927@csrd.uiuc.edu> bliss@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