隐式声明警告:内置函数是什么?(implicit declaration warning: What are the built

编程入门 行业动态 更新时间:2024-10-28 17:21:01
隐式声明警告:内置函数是什么?(implicit declaration warning: What are the built-in functions?)

问题界面正在标记许多“可能已经有你答案的问题”,但我试图尽职尽责地检查是否有人问我到底在哪里。 如果这是重复,我道歉。

假设我有以下不正确的程序:

extern void undefined_function(void); int main(int argc, char **argv) { undefined_function(); undeclared_function(); exit(0); }

用gcc编译给出:

$ gcc warnings.c warnings.c: In function ‘main’: warnings.c:6:2: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default] /tmp/ccVzjkvX.o: In function `main': warnings.c:(.text+0x15): undefined reference to `undefined_function' warnings.c:(.text+0x1f): undefined reference to `undeclared_function' collect2: ld returned 1 exit status $

我知道为什么会发出这些警告,以及如何纠正它们 - 这不是我的问题。

从输出中可以清楚地看出,gcc正在将exit()与其他未定义/未声明的函数区别对待,因为它认为它是“内置函数”

对于给定的gcc,我如何判断gcc认为是“内置函数”的函数列表是什么? 它是c标准库函数列表还是别的?

我考虑做nm libc.so ,但是在我的Ubuntu VM上,这个glibc似乎被剥离了,所以在这方面没有有用的信息:

$ nm /lib/x86_64-linux-gnu/libc.so.6 nm: /lib/x86_64-linux-gnu/libc.so.6: no symbols $

The question-asking interface is flagging many "Questions that may already have your answer", but I have attempted to do due diligence to check if any are asking exactly what I am here. My apologies if this is a duplicate.

Suppose I have the following incorrect program:

extern void undefined_function(void); int main(int argc, char **argv) { undefined_function(); undeclared_function(); exit(0); }

Compiling with gcc gives:

$ gcc warnings.c warnings.c: In function ‘main’: warnings.c:6:2: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default] /tmp/ccVzjkvX.o: In function `main': warnings.c:(.text+0x15): undefined reference to `undefined_function' warnings.c:(.text+0x1f): undefined reference to `undeclared_function' collect2: ld returned 1 exit status $

I know why these warnings are emitted, and how to correct them - that is not my question.

From the output, it is clear that gcc is treating exit() differently to the other undefined/undeclared functions, because it considers it a "built-in function"

For a given gcc, how can I tell what the list of functions is that gcc considers to be "built-in functions"? Is it exactly the list of c standard library functions or something else?

I considered doing nm libc.so, but on my Ubuntu VM, this glibc appears to be stripped, so there is no useful information there in this regard:

$ nm /lib/x86_64-linux-gnu/libc.so.6 nm: /lib/x86_64-linux-gnu/libc.so.6: no symbols $

最满意答案

该列表很长,而且非常特定于平台。 C标准库中的许多(但并非全部)函数(有时)被视为内置函数。 但是,还有一大堆与特定处理器指令和其他硬件功能相关的内置函数。 它们记录在从这里链接的各种页面中; 特别是,请看这里, 这里, 这里, 这里和这里。

The list is quite long, and quite platform-specific. Many (but by no means all) of the functions in the C standard library are (sometimes) treated as built-ins. But there are also a raft of built-in functions that relate to specific processor instructions and other hardware features. They're documented in various pages linked from here; in particular, see here, here, here, here, and here.

更多推荐

本文发布于:2023-07-25 23:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1267556.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   声明   隐式   implicit   warning

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!