Use of GUID constants

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 10 07:48:14 PST 2016


On Thursday, 10 March 2016 at 14:52:16 UTC, KlausO wrote:
> For GUIDs you often have to take the address (e.g. for calls to 
> QueryInterface), so I think phobos does not correctly implement 
> this.

Yes, that was my meaning.


> Is the above pair (const GUID and static member) the right way 
> to declare this idiom or would the following be better ?
> Both compile and seem to be equivalent (in terms of achieving 
> the same goal):
>
> enum IID IID_IServiceProvider = { 0x6d5140c1, 0x7436, 0x11ce, [ 
> 0x80, 0x34, 0x00, 0xaa, 0x00, 0x60, 0x09, 0xfa ] };
>
> interface IServiceProvider : IUnknown
> {
> 	static immutable GUID iid = IID_IServiceProvider;
> public:
> /* [local] */ HRESULT QueryService(
> /* [in] */ in GUID* guidService,
> /* [in] */ in IID* riid,
> /* [out] */ void **ppvObject);
> }
>

Personally I would just declare one immutable value in module 
scope and be done with it. It really just doesn't matter. Unless 
you're following some sort of style guide, personal preference 
rules the day. I don't know if Rainers has a special reason for 
what he did with the Visual D code or if it was personal 
preference.

As for Phobos, the Win32 API in Phobos as it stands now was a 
recent addition. Though it existed as a third-party package for 
several years, it may still have some kinks to work out and may 
not follow the Phobos style guide in some places.


More information about the Digitalmars-d-learn mailing list