Printf long long int in C with GCC?

左心房为你撑大大i 提交于 2019-11-27 05:24:02

问题


How do I printf long long int and also unsigned long long int in C99 using GCC?

I have searched the other posts which suggest to use %lld but it gives these warnings:

warning#1: unknown conversion type character 'l' in format [-Wformat]|
warning#2: too many arguments for format [-Wformat-extra-args]|

For the following attempt:

#include <stdio.h>

int main()
{
   long long int x = 0;
   unsigned long long int y = 0;
   printf("%lld\n", x);
   printf("%llu\n", y);
}

回答1:


If you are on windows and using mingw, gcc uses the win32 runtime, where printf needs %I64d for a 64 bit integer. (and %I64u for an unsinged 64 bit integer)

For most other platforms you'd use %lld for printing a long long. (and %llu if it's unsigned). This is standarized in C99.

gcc doesn't come with a full C runtime, it defers to the platform it's running on - so the general case is that you need to consult the documentation for your particular platform - independent of gcc.




回答2:


Try to update your compiler, I'm using GCC 4.7 on Windows 7 Starter x86 with MinGW and it compiles fine with the same options both in C99 and C11.




回答3:


You can try settings of code::block, there is a complier..., then you select in C mode.



来源:https://stackoverflow.com/questions/13590735/printf-long-long-int-in-c-with-gcc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!