cgccunsignedint64

Why does "unsigned int64_t" give an error in C?


Why does the following program give an error?

#include <stdio.h>

int main() 
{
    unsigned int64_t i = 12;
    printf("%lld\n", i);
    return 0;
}

Error:

 In function 'main':
5:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'i'
  unsigned int64_t i = 12;
                   ^
5:19: error: 'i' undeclared (first use in this function)
5:19: note: each undeclared identifier is reported only once for each function it appears in

But, If I remove the unsigned keyword, it's working fine. So, Why does unsigned int64_t i give me an error?


Solution

  • You cannot apply the unsigned modifier on the type int64_t. It only works on char, short, int, long, and long long.

    You probably want to use uint64_t which is the unsigned counterpart of int64_t.

    Also note that int64_t et al. are defined in the header stdint.h, which you should include if you want to use these types.