Author: Omid David Tabibi
Date: 16:08:36 07/28/03
Go up one level in this thread
On July 28, 2003 at 19:00:41, Dieter Buerssner wrote: >On July 28, 2003 at 18:26:29, Gerd Isenberg wrote: > >>References, function inlining and namespaces are enaugh to use C++. > >Gerd, references is enough for me, to avoid C++. In the "old days", when I read >code with a function call, like foo(a), I was sure, that a will be the same >after the function call, than before. With C++, I cannot be sure anymore. If I >want to make a changable by a function call, I use &a in C. All pretty much self >documenting. Just recently I changed some of functions from reference to pointer, just to eliminate this confusion! But there are cases that even you might prefer using references, for example when you pass a large object as an argument to a function, but do not intend to change its contents. What do ou do? passing by value is inefficient, and foo(&a) is confusing for the reasons you mentioned (the reader might get the impression that a is changing in foo. The best choice is to pass it by reference. Then you write foo(a), which looks just like passing by value, while it works exactly as efficient as sending a pointer. >Not anymore in C++. > >It may even be a performance issue. I read your suggestion about the small >inline functions vs. macros. I basically agree. But when using reference >paramaters (your example did), things might be very different. This might make >it very difficult or even impossible to make a good optimization for the >compiler. I'm afraid I didn't get this point. What is the practical difference between passing by reference, and sending a pointer? > >Function inlining is part of the ISO C Standard of 1999. Not all compilers >support it. > >Regards, >Dieter
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.