Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - Benign (and useful) redefinition of function implementations rejected ...
// In header char *someFunc(char *arg); // In implementation file char *someFunc(char *const arg) { ... Do something } Redefining to const means that arg cannot be changed, albeit that its contents can. This tactic is used in general in functions whereby you may access the argument in more than one point within the function body, and wish to protect yourself (or rather the implementation) from maintenance "improvements", in which someone may carelessly reuse one of the function arguments to avoid a frame variable (often from a misguided sense of efficiency), thereby invalidating the axioms of your implementation. Most of the other compilers to hand happily allow this. DMC++, alas, does not. It is my belief, though it's been a _long_ time since I dealt with this issue, that it is standard compliant. btw, all please not that this is not advocating // In implementation file char *someFunc(char const *arg) { ... Do something } as that is an entirely different semantic from the perspective of the the caller. A simpler way to look at this is // In header int someFunc(int arg); // In implementation file int someFunc(int const arg) { ... Do something } I've not run this through DMC++, but I presume it would behave the same. Any chance of a fix, Walter? Jun 11 2003
Are you saying it should or should not compile it? "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bc7ec6$27ln$1 digitaldaemon.com...// In header char *someFunc(char *arg); // In implementation file char *someFunc(char *const arg) { ... Do something } Redefining to const means that arg cannot be changed, albeit that its contents can. This tactic is used in general in functions whereby you may access the argument in more than one point within the function body, and wish to protect yourself (or rather the implementation) from maintenance "improvements", in which someone may carelessly reuse one of the function arguments to avoid a frame variable (often from a misguided sense of efficiency), thereby invalidating the axioms of your implementation. Most of the other compilers to hand happily allow this. DMC++, alas, does not. It is my belief, though it's been a _long_ time since I dealt with Jun 11 2003
Should "Walter" <walter digitalmars.com> wrote in message news:bc7v9l$2ofs$1 digitaldaemon.com...Are you saying it should or should not compile it? "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bc7ec6$27ln$1 digitaldaemon.com...// In header char *someFunc(char *arg); // In implementation file char *someFunc(char *const arg) { ... Do something } Redefining to const means that arg cannot be changed, albeit that its contents can. This tactic is used in general in functions whereby you Jun 11 2003
Walter schrieb...Are you saying it should or should not compile it? Jun 12 2003
Thanks, that's pretty clear. -Walter "Heinz Saathoff" <hsaat bre.ipnet.de> wrote in message news:MPG.195246a5927aaca79896c0 news.digitalmars.com...Walter schrieb...Are you saying it should or should not compile it? Jun 12 2003
|