平时用的都是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. HomeWork2

    程序一: 1 public intfindLast(int[] x, inty) { 2 //Effects: If x==null throw NullPointerException 3 // e ...

  2. linux 输出重定向一份到本地文件,屏幕继续输出

    ls -al 2>&1 | tee xLog

  3. Android内存性能优化(内部资料总结) eoe转载

    刚入门的童鞋肯能都会有一个疑问,Java不是有虚拟机了么,内存会自动化管理,我们就不必要手动的释放资源了,反正系统会给我们完成.其实Java中没有指针的概念,但是指针的使用方式依然存在,一味的依赖系统 ...

  4. Java Io 之 编码

    Java字符串编码一些知识总结: package com.dcz.io; import java.io.UnsupportedEncodingException; public class Encod ...

  5. HTTP及状态码汇总

    什么是HTTP: HTTP(HyperText Transfer Protocol超文本传输协议)是互联网上应用最为广泛的一种网络协议.所有的WWW文件都必须遵守这个标准,为了提供一种发布和接收HTM ...

  6. Github如何删除repository(仓库)

    首先就是你的Github主页了. 第二步点击进入一个repository(仓库) 第三步点击右上的setting 将此页面滑动到最下面找个这个 点击删除即可!

  7. Internet与www的关系

    Internet是把分布于世界各地不同结构的计算机网络用各种传输介质相互连接起来的网络. 因此,被称为网络的网络.Internet提供的主要服务有万维网(WWW.)文件传输(FTP.)电子邮件(E-m ...

  8. mysql 时间戳 按周、日、月 统计方法 附 date格式

    create_time时间戳格式 SELECT FROM_UNIXTIME(create_time,'%Y%u') weeks,COUNT(id) COUNT FROM role GROUP BY w ...

  9. COGS 902 乐曲主题 题解 & hash入门贺

    [题意] 给定一个长为n的序列,元素都是不超过88的正整数,求序列中主题的最大长度. 所谓主题是指在序列中出现了至少两次并且不相交的子串.特别的,主题可以变调,也就是说如果一个子串全部加上或减去一个数 ...

  10. git config proxy

    $ export http_proxy=http://proxy.ip.ad.ress:portnumber/ $ export https_proxy=http://proxy.ip.ad.ress ...