On Wed, 28 Apr 2004, Arkady V.Belousov wrote:

>      Bart, what wrong with next macroses?

the plural of macro is "macros".

> ______________O\_/_________________________________\_/O______________
> #include <limits.h>
>
> #define lonibble(v) (0x0f & (v))
> >--------------------^^^^^^
> #define hinibble(v) (0xf0 & (v))

hinibble is ambiguous. Suppose I use
hinibble(0x1234)
with your macro I get 3 and not 1.

This is why I tend to stay away from these macros. With
0x1234 & 0xf0
I understand immediately what it becomes. Otherwise I have to look up the
macro itself.

> #if CHAR_BIT == 8
> # define lobyte(v) ((UBYTE)(v))
> #else
> # define lobyte(v) (UBYTE)(0xff & (v))
> #endif
> #define hibyte(v) lobyte ((v) >> 8u)

same problem here. hibyte(0x12345678) = 0x56 ????

>
> #if USHRT_MAX == 0xFFFF
> # define loword(v) ((unsigned short)(v))
> #else
> # define loword(v) (unsigned short)(0xFFFF & (v))
> #endif
> #define hiword(v) loword ((v) >> 16u)

how about hiword(0x12345678abcdef01)?

> These macroses allow to make more readable

I don't agree.

> more portable

Not at all. v & 0xff is the most portable construct.

> and, in some cases, more effective code.

When? Do you mean that Turbo C puts in stupid code such as
and ax, 65535?
well that's the compiler's fault, not ours.

> ______________O\_/_________________________________\_/O______________
> #ifdef WITHFAT32
>     put_unsigned((unsigned)(clussec >> 16), 16, 4);
> #endif
>     put_unsigned((unsigned)(clussec & 0xffffu), 16, 4);
> _____________________________________________________________________
>               O/~\                                 /~\O
>
> You may wrote:
>
> ______________O\_/_________________________________\_/O______________
> #ifdef WITHFAT32
>     put_unsigned(hiword (clussec), 16, 4);
> #endif
>     put_unsigned(loword (clussec), 16, 4);
> _____________________________________________________________________
>               O/~\                                 /~\O

I think it should just be:

#ifdef WITHFAT32
    put_unsigned(clussec >> 16, 16, 4);
#endif
    put_unsigned(clussec & 0xffffu, 16, 4);

as Turbo C is too stupid to realize that these two values do not lose any
significant digits I'm forced to disable that warning using -w-sig...

> ______________O\_/_________________________________\_/O______________
> #ifndef I86                     /* the latter assumes byte ordering */

This code was already reorganized completely.

Bart



-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
Freedos-kernel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freedos-kernel

Reply via email to