C++ coding conventions: namespaces, references and getters (was Re: [PATCH 2/2] Introduce beginnings of a pipeline class.)

Gabriel Dos Reis gdr@integrable-solutions.net
Sat Aug 3 04:38:00 GMT 2013


On Tue, Jul 30, 2013 at 4:30 AM, Martin Jambor <mjambor@suse.cz> wrote:

>> I'm voting for references.  References can be seen as yet another
>> software structuring tool that instantly communicate some properties
>> such as you mentioned above.  In addition to that it's also a hint of
>> ownership, i.e. if I get an object& from somewhere I know that I better
>> not even think about whether to delete it or not.
>>
>
> well, let me stress again that we should think about this in the
> context of GCC.  In GCC, we are used to C semantics of the dot
> operator and have a lot of existing code that we will continue to use
> and mix with new code with the same assumption.  Putting a reference
> where none has been before might result in silent and hard to spot
> erroneous modifications.

I cannot make sense of this.

> At the same time, we are used to lookup whether the pointer we got can
> be NULL or not if necessary.  Moreover, in GCC, NULL-dereferences are
> not particularly dangerous and are easy to debug.

That should not be reason to avoid idiomatic constructions.

> In the context of GCC, there will be no ownership hints of this kind
> simply because new code will co-exist with tons of old code which uses
> pointers and will not give any such hints and so you can't assume you
> could free its pointers.  Let me not even mention GC.

References are not just about ownership (though they might imply it).


-- Gaby



More information about the Gcc-patches mailing list