Newsgroups: comp.lang.c++ Path: utzoo!censor!geac!alias!barney!rae From: Reid Ellis Subject: Re: calling main in ANSI C Message-ID: Keywords: More on const. Sender: Reid Ellis Reply-To: Reid Ellis Organization: Alias Research, Inc. Toronto ON Canada References: <814@atcmpe.atcmp.nl> <535@taumet.com> <1990Dec4.055744.2191@cbnewsm.att.com> Distribution: usa Date: 8 Dec 90 19:51:54 GMT Gregory P. Kochanski writes: >void x(array& q) >{ > q[0] = q[1]; >... > q[2] = q[3]; >... >} > >Now, on half of these calls, we're just 'reading' from the array, >but we're still paying the heavy overhead for the non-const functions. >Admittedly, they could just as well be written as >q[0] = ((const array&)q)[1], You could also write the following: void x(array& q) { const array &qc = q; q[0] = qc[1]; ... q[2] = qc[3]; ... } But your 'array' class better not make any strange assumptions about 'clean' and 'dirty' arrays [i.e. the 'const' method should access the actual data, not some sort of cached value, unless you're remembering the array's current "dirtiness". Reid -- Reid Ellis 176 Brookbanks Drive, Toronto ON, M3A 2T5 Canada rae@gpu.utcs.toronto.edu || rae%alias@csri.toronto.edu CDA0610@applelink.apple.com || +1 416 446 1644