🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Alan Griffiths Tue, 24 Oct 1995 00:22
relaxing const match on function implementation
#2289
Author: Alan Griffiths
Date: Tue, 24 Oct 1995 00:22
37 lines
2043 bytes
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. ]
Re: relaxing const match on function implementation
#2298
Author: John Max Skaller
Date: Wed, 25 Oct 1995 05:34
47 lines
1848 bytes
Alan Griffiths <aGriffiths@ma.ccngroup.com> wrote:
>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.

   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.
   

>This should not break any existing code.

    It can, but too bad -- it IS the status quo now in C++
and always was in ISO C.

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

    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. :-)


-- 
John Max Skaller               voice: 61-2-566-2189
81 Glebe Point Rd              fax:   61-2-660-0850
GLEBE NSW 2037                 email: maxtal@suphys.physics.oz.au
AUSTRALIA                      email: skaller@maxtal.com.au




---
[ 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. ]
Re: relaxing const match on function implementation
#2381
Author: Alan Griffiths
Date: Wed, 01 Nov 1995 19:04
32 lines
1694 bytes
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. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads