Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

return value of __BIT(x)



 Hi, all.

 "man __BIT" says:


> SYNOPSIS
>      #include <sys/param.h>
>      #include <sys/cdefs.h>
> 
>      uint32_t
>      __BIT(n);
> 
>      uint32_t
>      __BITS(m, n);

but the definitions are:

> /* __BIT(n): nth bit, where __BIT(0) == 0x1. */
> #define __BIT(__n)      \
>     (((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : ((uintmax_t)1 << 
> (uintmax_t)(__n)))
> 
> /* __BITS(m, n): bits m through n, m < n. */
> #define __BITS(__m, __n)        \
>         ((__BIT(MAX((__m), (__n)) + 1) - 1) ^ (__BIT(MIN((__m), (__n))) - 1))

uintmax_t is uint64_t, so these macros return uint64_t.

 What should we do?

  0) fix manpage

  1) any other solutions

--- test program -------
#include <sys/param.h>
#include <sys/cdefs.h>
#include <stdio.h>

int
main(int argc, char *argv[])
{
        unsigned int x;

        x = __BITS(17, 4);

        printf("%x\n", 123ULL);
        printf("%x\n", __BITS(17,4));
        printf("%llx\n", __BITS(17,4));

        return 0;
}

> % gcc -Wall bits.c -o bits
> bits.c: In function 'main':
> bits.c:12:2: warning: format '%x' expects type 'unsigned int', but argument 2 
> has type 'long long unsigned int'
> bits.c:12:2: warning: format '%x' expects type 'unsigned int', but argument 2 
> has type 'long long unsigned int'
> bits.c:13:2: warning: format '%x' expects type 'unsigned int', but argument 2 
> has type 'long long unsigned int'
> bits.c:13:2: warning: format '%x' expects type 'unsigned int', but argument 2 
> has type 'long long unsigned int'


--------------------------



-- 
-----------------------------------------------
                SAITOH Masanobu (msaitoh%execsw.org@localhost
                                 msaitoh%netbsd.org@localhost)


Home | Main Index | Thread Index | Old Index