zoukankan      html  css  js  c++  java
  • Ubuntu gcc编译报错:format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘__time_t’ [-Wformat=]

    平时用的都是Centos系统,今天偶然在Ubuntu下编译了一次代码,发现报错了:

    源码:

    #include <stdio.h>
    #include <sys/time.h>
    #include <time.h>
    
    int main(int argc,char * argv[])
    {
        struct timeval tv;
        gettimeofday(&tv,NULL);
        printf("time %u:%u
    ",tv.tv_sec,tv.tv_usec);
        return 0;
    }

    这样几行代码,按理说不应该有错的,错误信息:

    warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘__time_t’ [-Wformat=]
      printf("time %u:%u
    ",tv.tv_sec,tv.tv_usec);warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘__suseconds_t’ [-Wformat=]

    开始的时候没有注意到错误信息最后的[-Wformat=]提醒,一直以为是类型匹配错了,把%u改成了%llu仍旧是不行。最后才注意到提醒。

    然后在Ubuntu官网找到了原因:

    NOTE: In Ubuntu 8.10 and later versions this option is enabled by default for C, C++, ObjC, ObjC++.  To disable, use -Wformat=0.

    然后在编译的时候改成了:gcc test.c -Wformat=0 就没问题了。Wformat这个配置在Centos下默认是关闭的,所以一直没报错,如果编译的时候打开,也会提示一样的错误。

    看来不同的平台,很多默认的设置还是不一样的。

    Ubuntu官网的解释:http://manpages.ubuntu.com/manpages/oneiric/en/man1/gcc.1.html

  • 相关阅读:
    day3 程序流程控制
    day2 程序流程控制
    String.prototype.formatWith
    未能找到文件“in oslyncsc.exe”
    Azure DocumentDB
    查询表中所有字段的最大长度(大数据情况)
    查询表中所有字段的最大长度
    linux开发
    sql server cvs 导入
    清除“远程桌面连接”的历史记录
  • 原文地址:https://www.cnblogs.com/likui360/p/5275203.html
Copyright © 2011-2022 走看看