Topic: relaxing const match on function implementation


Author: Alan Griffiths <aGriffiths@ma.ccngroup.com>
Date: 1995/11/01
Raw View
In article <46kdsh$b1v@oznet07.ozemail.com.au>
           maxtal@suphys.physics.su.oz.au "John Max Skaller" writes:

>    You are correct. This IS the case in ISO C. It also IS
> the case in C++ now. In particular the declarations:
>
>    void f(int);
>    void f(int const);
>    void f(const int);
>
> declare the same function.
>
>     I voted in favour of the change to the ARM to bring
> C++ into line with ISO C so I guess I think it
> is a good idea. :-)

Sorry, it didn't compile (3 different compilers) and when I checked ARM...

I know I should look in the draft standard (but the copy to hand is in
Acrobat and slow to use).

--
Alan Griffiths               | Also editor of: The ISDF Newsletter
Senior Systems Consultant,   | (An Association of C and C++ Users publication)
CCN Group Limited.           | (ISDF editor  : isdf@octopull.demon.co.uk)
(agriffiths@ma.ccngroup.com) | (For ACCU see : http://bach.cis.temple.edu/accu)

---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]





Author: Alan Griffiths <aGriffiths@ma.ccngroup.com>
Date: 1995/10/24
Raw View
In the interests of hiding implemetation details it seems to me that
a function that does not amend an object passed as a formal parameter
should be able to declare that parameter as "const" without requiring
the same of a function prototype.

For example:

void f(int a);   // prototype in a shared header file.

void f(const int a) {}  // Implementation of above.

This relaxation would allow the compiler to verify the use of "a" within
the function body without cluttering up the interface declaration with
"const" keywords which do not impact client code.

This should not break any existing code.

Is this a good idea, or am I missing something?

PS

The relaxation only applies to the parameters _not_ to (for example) the
objects that the parameters reference.

e.g. void f(const int& a) {}  doesn't match  void f(int& a);
     void f(int* const a) {}  matches        void f(int* a);

--
Alan Griffiths               | Also editor of: The ISDF Newsletter
Senior Systems Consultant,   | (An Association of C and C++ Users publication)
CCN Group Limited.           | (ISDF editor  : isdf@octopull.demon.co.uk)
(agriffiths@ma.ccngroup.com) | (For ACCU see : http://bach.cis.temple.edu/accu)

---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]