平时用的都是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\n",tv.tv_sec,tv.tv_usec);
return ;
}

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

warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument  has type ‘__time_t’ [-Wformat=]
printf("time %u:%u\n",tv.tv_sec,tv.tv_usec);warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 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

Ubuntu gcc编译报错:format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘__time_t’ [-Wformat=]的更多相关文章

  1. MAC 下用GCC编译报错:“Undefined symbols for architecture x86_64: ”

    解决方法: 因为GCC编译的时候没有链接C++ standard library, 因此在编译的时候要加入符号 -lstdc++ 使用命令: gcc myprog.c -o myprog -lstdc ...

  2. CentOS7安装mysql8.0编译报错集合

    以下都是我安装mysql8.0遇到的一些报错和解决方法 1.does not appear to contain CMakeLists.txt. 原因:mysql下载的源码包不对 解决方法:下载正确的 ...

  3. 安装hue时,make apps 编译报错

    安装hue时,make apps 编译报错 :"Error: must have python development packages for 2.6 or 2.7. Could not ...

  4. redis编译报错总结

    redis编译报错总结: 1.不能编译没有GCC 编译工具安装报错:问题1:make时可能会报如下错误cc -c -std=c99 -pedantic -O2 -Wall -W   -g -rdyna ...

  5. openWRT编译报错集锦

    需网络稳定,可正常上梯子. /*ubuntu18编译报错:*/ autoreconf: running: /home/jack/openwrt-sdk/staging_dir/host/bin/aut ...

  6. 使用C#模拟Outlook发送邮件,代码编译报错

    添加OutLook API using OutLook = Microsoft.Office.Interop.Outlook; 发送邮件方法 public void SendEmail() { Out ...

  7. cordova编译报错:Execution failed for task ':processDebugResources'

    cordova编译报错:Execution failed for task ':processDebugResources' 引发这个错误的最扩祸首就是一个中文命名的文件,不知道什么时候加入的,我写了 ...

  8. 编译报错dereferencing pointer to incomplete type

    关于编译报错“dereferencing pointer to incomplete type... 多是没找到结构体的定义,可以在本地复制其定义试试. 参考: http://my.oschina.n ...

  9. Maven-010-maven 编译报错:Failure to ... in ... was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced.

    今晚在编译 maven 项目的时候,命令行报错,出现 Failure to ... in ... 类似错误,详细的错误信息如下所示: [INFO] -------------------------- ...

随机推荐

  1. Mac 用户组:staff、 wheel、admin 的区别

    所有的用户都属于 staff 组, 只有具有管理员性质的用户位于 wheel 组中. wheel 是一个特殊的用户组,该组的用户可以使用 su 切换到 root,而 staff 组是所有普通用户的集合 ...

  2. SQL server 语句新建用户、对用户授权、删除用户实例

    Grant select on tb to db_user --给db_user用户授权 tb表 查询权限 一.命令操作 USE mydb GO --1. 新建测试用户 --1.1 添加登录用户和密码 ...

  3. BZOJ1452——[JSOI2009]Count

    1.题目大意: 就是给一个n×m的方格,然后一些平面上的 求和 修改操作 2.分析:二维树状数组裸题 #include <cstdio> #include <cstdlib> ...

  4. Android学习笔记(十一)——ListView的使用(下)

    //此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! ListView 这个控件比较复杂, 就是因为它有很多的细节可以优化,下面我们在试试提高它的运行效率:一.提高 ...

  5. jquery版悬浮模块demo

    在做在线客服时,代码就是按照该模块命名.现在,我要添加一个返回主页的功能,我觉得再复制一遍之前的代码,那个量有点多,如果我再添加一个功能,那个量会很多……现在我用创建对象字面量的方式来创建(其实我还想 ...

  6. 深入Activity,Activity启动模式LaunchMode完全解析

    转载请注明出处:http://blog.csdn.net/linglongxin24/article/details/53221384本文出自[DylanAndroid的博客] 在平时的开发中,我们可 ...

  7. Android界面刷新之invalidate与postInvalidate的区别

    Android的invalidate与postInvalidate都是用来刷新界面的. 在UI主线程中,用invalidate():本质是调用View的onDraw()绘制. 主线程之外,用postI ...

  8. Unity3D绑定button监听事件

    一.可视化创建及事件绑定 第一步:通过Hierarchy面板创建button,如图 第二步:创建一个脚本名为TestClick,并定义一个名为Click的public方法 ? 1 2 3 4 5 6 ...

  9. IOI2015 Boxes

    Description 给出一个环形,n个点,每次只能访问k个点,求最短距离. Sol 贪心. CCF的题解. 首先只会最多走一趟环形,根据抽屉原理,如果一边不足k个才会到另一边,所以对于第二次以上的 ...

  10. vim帮助手册汉化

    vim帮助手册汉化 vim帮助手册汉化 下载vimcdoc-1.9.0.tar.gz 安装vimcodc-1.9.0 vim命令模式下输入help可以查看vim的帮助手册.美中不足的是这个帮助手册是英 ...