[gmpi] Re: Linux C++ question

  • From: Paul Davis <paul@xxxxxxxxxxxxxxxxxxxxx>
  • To: gmpi@xxxxxxxxxxxxx
  • Date: Wed, 23 Feb 2005 16:33:48 -0500

>A few more stylistic nits:
>
>[1] For in arguments, I like to use const references.  Pointers are
>reserved for out.  That gives a very handy way of knowing, at the call
>site, what might change and what might not.  So:
>
>GMPI_Factory::CreateInstance( const GMPI_GUID& iid, ... )
>
>Note that a reference is the same as a pointer in C, or at least that's
>how they do it in COM.  They declare the interface as const GUID*, but
>the impl can be const GUID&.

the best rule of thumb for this that i have seen is from meyers. the
rule is that if the object being passed as an argument can be null,
use a pointer, otherwise, use a reference. as far as in/out arguments,
i agree that if arguments are clearly "in", then const is
appropriate. its not always clear, however.

>Lastly, I still like to use NULL instead of 0 for pointers.  I know in
>C++ you can use 0, but it's an old habit that helps reinforce that you
>are dealing with a pointer.

many C++ authorities advise against this because of the difficulty of
defining NULL acceptably.

--p


----------------------------------------------------------------------
Generalized Music Plugin Interface (GMPI) public discussion list
Participation in this list is contingent upon your abiding by the
following rules:  Please stay on topic.  You are responsible for your own
words.  Please respect your fellow subscribers.  Please do not
redistribute anyone else's words without their permission.

Archive: //www.freelists.org/archives/gmpi
Email gmpi-request@xxxxxxxxxxxxx w/ subject "unsubscribe" to unsubscribe

Other related posts: