digitalmars.D.learn - const parameter passing?
- Serg Kovrov (16/16) Jan 25 2006 Hi All,
- Sean Kelly (4/7) Jan 25 2006 No. To achieve this in D you would have to pass a copy of the object to...
- Oskar Linde (3/10) Jan 25 2006 You could also possibly pass the object through a read-only interface.
- Craig Black (3/3) Jan 25 2006 Perhaps someone good with D templates could come up with a Const templat...
- nick (3/24) Jan 29 2006 I think D's philosophy is that this sort of thing is best left to tools
- Serg Kovrov (5/22) Jan 31 2006 Thanks, I just curious what this 'lint' thing is, where to get it? But
- Derek Parnell (12/36) Jan 31 2006 'lint' is a utility program for C and C++ programs. It does a very thoro...
- Carlos Santander (4/12) Jan 31 2006 Didn't Ben write one?
Hi All, Is there any way to prevent modification of object passed into function? In C++ we have to do something like this: void test(const Test& t) { int i = t.i; // ok t.i = 0; // compile time error // or i = t.get(); // ok t.set(0); // compile time error } But in D there is no 'const' function call parameter. Unfortunately 'in' parameter didn't do the job. ps. Sorry for possible duplicate of question - this newsgroup's search is really bad =( --serg
Jan 25 2006
Serg Kovrov wrote:Hi All, Is there any way to prevent modification of object passed into function?No. To achieve this in D you would have to pass a copy of the object to the function. D has no concept of logical const-ness. Sean
Jan 25 2006
Sean Kelly wrote:Serg Kovrov wrote:You could also possibly pass the object through a read-only interface. /OskarHi All, Is there any way to prevent modification of object passed into function?No. To achieve this in D you would have to pass a copy of the object to the function. D has no concept of logical const-ness.
Jan 25 2006
Perhaps someone good with D templates could come up with a Const template that would provide read only access to an object. -Craig
Jan 25 2006
Serg Kovrov wrote:Hi All, Is there any way to prevent modification of object passed into function? In C++ we have to do something like this: void test(const Test& t) { int i = t.i; // ok t.i = 0; // compile time error // or i = t.get(); // ok t.set(0); // compile time error } But in D there is no 'const' function call parameter. Unfortunately 'in' parameter didn't do the job. ps. Sorry for possible duplicate of question - this newsgroup's search is really bad =( --sergI think D's philosophy is that this sort of thing is best left to tools like lint.
Jan 29 2006
nick wrote:Serg Kovrov wrote:Thanks, I just curious what this 'lint' thing is, where to get it? But anyway, use of external tools for that purpose is not solution for me. -- serg.Is there any way to prevent modification of object passed into function? In C++ we have to do something like this: void test(const Test& t) { int i = t.i; // ok t.i = 0; // compile time error // or i = t.get(); // ok t.set(0); // compile time error } But in D there is no 'const' function call parameter. Unfortunately 'in' parameter didn't do the job.I think D's philosophy is that this sort of thing is best left to tools like lint.
Jan 31 2006
On Tue, 31 Jan 2006 23:30:49 +0200, Serg Kovrov wrote:nick wrote:'lint' is a utility program for C and C++ programs. It does a very thorough analysis of your code and warns you about things which the compiler does not report on. You can usually adjust the level of detail to be reported on. No one has written a 'lint' program for D yet, as far as I know. -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocracy!" 1/02/2006 10:00:12 AMSerg Kovrov wrote:Thanks, I just curious what this 'lint' thing is, where to get it? But anyway, use of external tools for that purpose is not solution for me.Is there any way to prevent modification of object passed into function? In C++ we have to do something like this: void test(const Test& t) { int i = t.i; // ok t.i = 0; // compile time error // or i = t.get(); // ok t.set(0); // compile time error } But in D there is no 'const' function call parameter. Unfortunately 'in' parameter didn't do the job.I think D's philosophy is that this sort of thing is best left to tools like lint.
Jan 31 2006
Derek Parnell escribió:'lint' is a utility program for C and C++ programs. It does a very thorough analysis of your code and warns you about things which the compiler does not report on. You can usually adjust the level of detail to be reported on. No one has written a 'lint' program for D yet, as far as I know.Didn't Ben write one? -- Carlos Santander Bernal
Jan 31 2006