Joerg Schilling wrote:
> James Carlson <[EMAIL PROTECTED]> wrote:
>
>   
>> Garrett D'Amore writes:
>>     
>>> I have macros like those above, yes. (Although in my code it looks more 
>>> like this:)
>>>
>>> #define BIT(x) (1UL << (x))
>>> ...
>>> #define MYMASK BIT(4)
>>>       
>> I'm surprised nobody's mentioned C structures with bit fields.  I've
>> used those to good effect on hardware in the past.  (Yes, getting the
>> access width right, particularly on writes, can be a pain on some
>> devices.)
>>     
>
> The C standard grants that these structures are not portable.....
>
> All known C-compilers give a limited portability if you take care of 
> declaring 
> them the right way.
>
> -     You need to use "unsigned char" as type unless you use the IBM 
>       C-compiler
>
> -     You may not define them to have more bits than an int
>
> -     You take care of alignement
>
> -     You take care about Bit-ordering (this may be different from Byte-order
>       see Plan 9 compiler...)
>   

Yeah,  I don't like to rely on ordering of the bits within the C 
structure.  C structures are fine for bit fields used only by software, 
but when the intent is to define a mapping to hardware registers, I find 
that #define's are a lot more portable.

And like Jim said, I usually just set up the defines for my hardware 
once, and forget about them.  I rarely use special macros.

    -- Garrett
> Cdrecord uses bitfields for SCSI structures but as you see from above, you 
> definitely need autoconf to get the right definition for the current compile 
> platform.
>
> Jörg
>
>   

_______________________________________________
opensolaris-code mailing list
opensolaris-code@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to