Re: [Cppunit-devel] A new architecture ?
Brought to you by:
blep
From: Duane M. <dua...@ma...> - 2001-10-22 21:23:46
|
--- At Mon, 22 Oct 2001 22:51:51 +0200, Bastiaan Bakker wrote: >Duane Murphy wrote: > >>--8<--- >>(3) Use of references. While pointers are evil, references are your >>friend. Const references are your best friend. They take up minimum >>space, they have maximum reliability (they cant be NULL), you cant modify >> >Hmm, AFAIK references take as much space as pointers. I suspect most >compilers translate references and pointers to the same code. They >certainly CAN be *NULL (and you'll segfault if you try to use them). >Personally I find having both pointers and references a not so elegant >feature of C++. But I must confess to have built up a distaste for many >C++ 'features' over the years and to prefer the simplicity of Java. You are absolutely correct, except for one piece. References are typically implemented in terms of pointers. I have never heard of one that wasnt but there is nothing that says it couldnt be. The part that is incorrect is that references can be NULL. A NULL reference is illegal. Through programming error you can certainly create a NULL reference, but that would be a programming error. ( There was an article in CUJ a few months ago in the "Conversations" column by Jim Hyslop and Herb Sutter but I cant seem to find an online reference to that article.) Pointers on the other hand can legally be NULL. There are places for pointers and places for references. If I can use references I will. If not I try and use counted pointers. I prefer automated memory management to relying on my own poor faculties. ..Duane |