home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!gatech!rpi!batcomputer!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
- From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Subject: Re: const on pass by value
- Message-ID: <9221212.10105@mulga.cs.mu.OZ.AU>
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- References: <1992Jul24.151010.11969@PacBell.COM> <9220801.5026@mulga.cs.mu.OZ.AU> <1992Jul28.180713.16258@mole-end.matawan.nj.us>
- Date: Thu, 30 Jul 1992 02:14:14 GMT
- Lines: 48
-
- mat@mole-end.matawan.nj.us writes:
-
- >In article <9220801.5026@mulga.cs.mu.OZ.AU>, fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
- >> mat@uunet.uu.net!mole-end writes:
- >>
- >> >In article <1992Jul24.151010.11969@PacBell.COM>, pjcondi@lepton (Paul Condie) writes:
- >> >> Should pass by value arguments be declared as "const" for
- >> >> good coding style? Or is that nit picking?
- >
- >> >> void foo (const int a);
- >> >> or
- >> >> void foo (int a);
- >> >
- >> >It's not nitpicking. It's part of something called const correctness.
- >> >Your program has it or doesn't. Programs that have it are almost immune
- >> >to a certain large family of errors.
- >
- >> Huh? In this example, it IS just nitpicking. How could the presence or
- >> absence of const in the declaration for foo affect the program's const
- >> correctness?
- >
- >It affects what version of overloads are applied to the variable/object
- >and the confidence of the reader that the variables are/are not changed.
-
- It does NOT affect what version of overloads are applies to the variable/object.
- For example:
-
- fergus> cat > test.c
- int foo(int a) { return a; }
- int foo(const int a) { return -a; }
-
- fergus> CC test.c
- "test.c", line 2: error: the overloading mechanism cannot tell a int (int ) from a int (const int )
-
- Furthermore the only reason why it might affect the confidence of the reader
- that the variables are not changed is if the reader does not understand the
- semantics of pass-py-value in C. (If this is the case then the reader,
- not the program, is broken :-). Besides, the "confidence of the reader" is
- a fairly dubious thing in general; this is very much a matter of style (ie.
- "nitpicking").
-
- Thus I still maintain that it IS just nitpicking.
-
- --
- 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!
-