Why "unsigned int64_t" gives an error in C?

msc picture msc · Jun 19, 2017 · Viewed 7.6k times · Source

Why the following program gives 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 unsigned int64_t i gives an error?

Answer

emlai picture emlai · Jun 19, 2017

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.