D and memory mapped devices

Russel Winder via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 14 01:10:57 PDT 2017


In C and C++ you often use bitfields to control devices with memory
mapped hardware control and data words. So for example:

typedef struct some_device {
    unsigned int flob: 3;
    unsigned int adob: 2;
    unsigned int: 3;
    unsigned int data: 8;
} some_device;

Clearly D has no bitfields. I know of std.bitfield, so somethign like:

struct some_device {
    uint a;
    mixin(bitfields!(
        uint, "flob", 3,
        uint, "adob", 2,
        uint, "someMadeUpNameBecauseBlankIsNotAcceptable", 3,
        uint, "data", 8));
}

but the bitfields mixin template appears to do more than add all the
bit twiddling functions to emulate the bitfields. This would appear a
priori to not allow for actual memory mapped devices using it, or am I
missing something? 

-- 
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/20170614/53255140/attachment.sig>


More information about the Digitalmars-d-learn mailing list