unsigned int32 linux - not supported
I want to use a unsigned int32, using gcc 4.3.3 on Ubuntu 9.04.
However, when I declare this:
开发者_Python百科unsigned int32 dev_number;
I get an compile error:
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘dev_number’
Any suggestions?
I'm sure exactly what you're trying to achieve. Are you trying to have an unsigned int called int32? Or are you trying to have an unsigned 32 bit integer variable?
In the latter case, you can try to use stdint.h, which defines a set of types guaranteed (I believe?) to contain at least the set of bits specified.
#include <stdint.h>
uint32_t my_var;
In the former case, I can't see why your line shouldn't work.
unsigned int32 = 42;
printf ("int32 = %u\n", int32);
prints int32 = 42
as expected.
HTH
In your code, use stdint.h as header file and use uint32_t instead of unsigned int32.
stdint.h is a standard header file introduced in the C99 standard library. It allows programmers to write more portable code by providing a set of typedefs that specify exact-width integer types, together with the defined minimum and maximum allowable values for each type, using macros. Please refer to wiki page here,
Here is sample code,
#include <stdio.h>
#include <stdint.h>
int main(void)
{
uint32_t i = 50;
printf("heloo world %d\n", i);
return 0;
}
I can reproduce your exact error with this line:
unsigned int32 dev_number = 0;
Are you sure you haven't written something like that? There is no int32
type in C.
If you want to declare an unsigned 32 bit variable, use uint32_t
and make sure you #include <stdint.h>
精彩评论