A compatible way to parse a 64-bit integer using sscanf with GCC

I compiled the following c program gcc -ansi -pedantic -Wall test.c :

 #include <stdio.h> #include <stdint.h> #define BUFFER 21 int main(int argc, char* argv[]) { uint64_t num = 0x1337C0DE; char str[BUFFER]; /* Safely Holds UINT64_MAX */ if(argc > 1) sscanf(argv[1],"%llu",&num); sprintf(str,"%llu",num); return 0; } 

And I get the following warnings:

 test.c:8:5: warning: ISO C90 does not support the 'll' gnu_scanf length modifier test.c:9:3: warning: ISO C90 does not support the 'll' gnu_printf length modifier 

What is the correct, C90 standard compliant, way to parse / print a 64-bit integer from / to a string,
which does not generate these warnings?

+4
source share
1 answer

No. The largest integer type in C 90 is long , which is guaranteed to be at least 32 bits. Since there is no integer type guaranteed to be at least 64 bits, it is also not possible to read a 64-bit integer in C90. Of course, long can be 64 bits (this was in at least one implementation, but there is no certainty that it is.

+6
source

Source: https://habr.com/ru/post/1489617/


All Articles