C/C++ 隐式申明 问题
在64bit 系统中,强烈建议加入以下选项,将 implicit-function-declaration 视为 error
-Werror=implicit-function-declaration
https://stackoverflow.com/questions/9182763/implicit-function-declarations-in-c
When C doesn't find a declaration, it assumes this implicit declaration: int f();
, which means the function can receive whatever you give it, and returns an integer. If this happens to be close enough (and in case of printf
, it is), then things can work. In some cases (e.g. the function actually returns a pointer, and pointers are larger than ints), it may cause real trouble.
Note that this was fixed in newer C standards (C99, C11). In these standards, this is an error. However, gcc
doesn't implement these standards by default, so you still get the warning.
C语言规定,对于没有声明的函数,自动使用隐式声明
C89 的规范中,是允许这种隐式函数声明,且 gcc 默认是按照 c89 的标准来编译程序的。
在 C99 的规范,已经不允许隐式函数声明了。所以如果你在用 gcc 编译的时候,加上 -std=c99 的时候,编译器马上会出现一个警告:隐式函数声明。
The reason is that implicitly declared functions have a return type of int
. Casting this int
value to a 64-bit pointer throws away 32 bit of the result.
This is the expected GNU C behavior, based on what C compilers for early 64-bit targets did. The sxtw
instruction is required to implement this behavior.
(Current C standards no longer have implicit function declarations, but GCC still has to support them for backwards compatibility with existing autoconf tests.)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
· 零经验选手,Compose 一天开发一款小游戏!
2020-03-30 TUN/TAP设备浅析
2020-03-30 Termianl 暂停
2020-03-30 解析 Linux 内核可装载模块的版本检查机制