Is there a standard way to determine the bit width of hardware?

Variables of type int are supposedly "one word of a machine type in length" but in embedded systems, C compilers for 8-bit microconsumption have int 16 bits !, (8 bits for unsigned char), then for more bits int behaves normally: in 16- bit int microns are also 16 bits, and 32 bit int microns - 32 bits, etc.

So, is there a standard way to test it, something like BITSIZEOF (int)?

like "sizeof" for bytes, but for bits.

That was my first idea.

    register c=1;                
    int bitwidth=0;
    do
    {

        bitwidth++;

    }while(c<<=1);

    printf("Register bit width is : %d",bitwidth);

c int, 8- , int 16 , 16 . , "int" " ", ( )

? , , 256 , 8, 16, 32 , ( , ) , ,

http://embeddedgurus.com/stack-overflow/category/efficient-cc/page/4/

( )

, - . , , C99 "" "". C99, , - . , , , .

+5
7

, . C99 stdint.h, , uint_fast8_t, , 256 .

, , , . , .

, .

+17
#include <limits.h>

const int bitwidth = sizeof(int) * CHAR_BIT;
+7

, , , - types.h stdint.h, , .

, uint32_t 32 , int8_t 8 .

+7

ISA, , , , . , autoconf/automake #ifdef, , .

+1

, " " int "" ". C (C89/90) int . register c register int c, C89/90. , C int -32767... + 32767 , , int 16 , .

... sizeof(int) * CHAR_BIT int.

, , int . , , INT_MIN INT_MAX.

P.S. , , CHAR_BIT.

+1

unsigned char unsigned short ? ? , .

0

, , . , .

0
source

All Articles