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 的时候,编译器马上会出现一个警告:隐式函数声明。

 

https://stackoverflow.com/questions/55351940/why-is-the-compiler-adding-an-extra-sxtw-instruction-resulting-further-in-a-k

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.)

 

posted @   sinferwu  阅读(485)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
· 零经验选手,Compose 一天开发一款小游戏!
历史上的今天:
2020-03-30 TUN/TAP设备浅析
2020-03-30 Termianl 暂停
2020-03-30 解析 Linux 内核可装载模块的版本检查机制
点击右上角即可分享
微信分享提示