C macros vs D can't do the right thing

Russel Winder via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 3 06:17:46 PDT 2017


A stripped down problem to avoid fluff. The C macro:

    #define FLOB(t) (sizeof(t))

Can be used in another macro:

    #define THINGY(a, b) (_THING(a, FLOB(b)))

We can use this as in:

    THINGY(10, __u32)

Now the D Way says use functions not macros. except that 

    size_t FLOB(T)(auto ref T t) { return t.sizeof; }

which is the result of DStep doesn't allow passing a type name as t.

Is this a problem in D or a problem in DStep?

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20170603/1363141e/attachment.sig>


More information about the Digitalmars-d-learn mailing list