- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
In computer software, an application binary interface (ABI) is an interface between two binary program modules; often, one of these modules is a library or operating system facility, and the other is a program that is being run by a user.
An ABI defines how data structures or computational routines are accessed in machine code, which is a low-level, hardware-dependent format; in contrast, an API defines this access in source code, which is a relatively high-level, relatively hardware-independent, often human-readable format. A common aspect of an ABI is the calling convention, which determines how data is provided as input to or read as output from computational routines; examples are the x86 calling conventions.
-- https://en.wikipedia.org/wiki/Application_binary_interface
我确信 Sys V ABI 规范(i386 和 AMD64)中描述的标准“函数调用序列”限制了 C 库中那些外部函数的调用,但它是否也限制了那些静态函数的调用?
这是一个例子:
$cat abi.c
#include<stdio.h>
typedef void (*ret_function_t)(int,int);
ret_function_t gl_fp = NULL;
static void prnt(int i, int j){
printf("hi from static prnt:%d:%d\n", i, j);
}
void api_1(int i){
gl_fp = prnt;
printf("hi from extern api_1:%d\n", i);
}
ret_function_t api_2(void){
return gl_fp;
}
$cat abi_main.c
#include<stdio.h>
typedef void (*ret_function_t)(int,int);
extern void api_1(int i);
extern ret_function_t api_2(void);
int main(){
api_1(1111);
api_2()(2222, 3333);
}
$gcc abi_main.c abi.c -o abi_test
$./abi_test
hi from extern api_1:1111
hi from static prnt:2222:3333
当 abi_main.c 调用 api_1 和 api_2 时,函数调用序列(包括寄存器使用、堆栈框架、参数传递、变量参数...)详细信息在 Sys V ABI 中定义,因为它们是外部的,但是调用在abi.c 中定义的静态函数prnt
?是属于ABI标准还是由编译器来决定?
最佳答案
是的,它们确实适用。静态函数只是具有翻译单元可见性的普通函数。 ABI 是编译器生成任务,C 标准故意对此只字未提。从您的代码中删除 static
词时,它会变得清晰。道理是一样的。这种方法的缺点是编译器无法检查链接正确性(调用者-被调用者),而只能检查其类型(void (*ret_function_t)(int,int);
)在编译时,因为您是在运行时链接的人。所以,不推荐。
发生的情况是您的编译器将为任何调用函数生成代码,遵循一些 ABI,我们称之为 ABI-a。它将生成代码根据其他一些 ABI 调用的函数,比方说 ABI-b。如果 ABI-a == ABI-b,那总是有效的,如果您使用相同的 ABI 编译两个文件,就会出现这种情况。
例如,如果 prnt
函数位于地址 0x12345678
,则此方法有效:
ret_function_t gl_fp = (ret_function_t)0x12345678;
只要在 0x12345678
处有一个带有正确参数的函数,它也可以工作。如您所见,该函数不能内联
d,因为编译器不知道哪个函数定义将在该内存点结束,可能有很多。
关于c - Sys V ABI 规范(i386 和 AMD64)中描述的标准 "Function Calling Sequence"是否适用于静态 C 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53958062/
在一个环境中,我有 pandas 版本 0.17.0 和 numpy 版本 1.10.1。在另一个环境中,我有 pandas 版本 0.18.1 和 numpy 版本 1.10.4。 我运行这段代码
This question already has answers here: Default stringify for objects, equivalent to Java's toString
我一直在尝试为我的profile命令嵌入设置一个人们可以更改的简历。我认为它应该有效,但我的代码似乎有问题。 相关代码如下: const PREFIX = '!'; var bio = {}; cli
我正在尝试获取网站图标、网站标题和外部 URL 列表的描述,最好使用 jquery。我已经成功地为我的网址同步了谷歌的图标服务,任何人都可以阐明如何实现网站标题和描述吗?这是我到目前为止获得图标的内容
我在尝试运行代码时收到错误。找不到问题出在哪里。我可能遗漏了一些小细节,如果您能纠正它那就太好了。 计算Servlet import java.io.IOException; impo
我的数据库中有两个字段,一个是描述(TEXT),另一个是short_desc(VARCHAR-200)。 当我显示搜索结果时,我显然使用了short_desc,当有人点击该项目时,他们会得到完整的描述
当我尝试通过ajax和Jquery调用 Controller 上的save方法时,我正在使用Spring MVC、Jquery、Hibernate和tomcat。单击“保存”按钮时,我在 tomcat
我试图使用describe()来获取一些描述性统计数据,但获取了应该是数字的nan值。 我尝试使用 axis=0 或 axis=1,而 axis=1 产生了正确的数值,但这不是正确的数值我需要; ax
我有超过 1 亿个字符串要存储在文件系统中。与字符串 (~255Chars utf8) 一起,将有两个日期和一些定义其属性的整数值。 我可以将它们放在一个 CSV 文件中,但它会很大。我可以将几个较小
有没有办法将 JavaScript 合并到 Jenkins 顶部的描述字段中? 每当我添加脚本标签时,当您查看源代码时,它都会被 Jenkins 删除。 如果有人有建议或方向指出我,那就太好了。
您如何获得 SEH 的名称和/或描述?异常无需必须将字符串硬编码到您的应用程序中? 我尝试使用 FormatMessage(),但它有时会截断消息,即使您指定忽略插入也是如此: __asm { //
如果我在 MySQL 中使用 CREATE TRIGGER 语法创建一个触发器,我该如何附加注释来描述它?我的意思是在声明中或之后对我来说是一样的。 我想不通。对于表格,您可以在声明末尾添加 COMM
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 8 年前。 Improve
当开发多媒体应用或者游戏应用的时候,需要使用音量控制键来设置程序的音量大小。在Android系统中有多中音频流,通过Activity中的函数 setVolumeControlStream(int s
Slick DSL 允许通过两种方式在表中创建可选字段。 对于这个案例类: case class User(id: Option[Long] = None, fname: String, lname:
如果不属于默认命名空间,我如何描述 pod 信息。使用默认命名空间我没有任何问题。 但我想获得与命名空间对齐的特定 pod 的信息。 但是,当我想描述我可以制作的同一个 pod 时,请参阅 我尝试使用
在我使用过的几乎所有 vim 副本中,程序都会在替换文本后给出更改的描述。 (例如,将显示类似“20 行 92 个替换”之类的内容。) 我现在正在使用默认情况下不这样做的 vim 副本。 是否有一个简
我正在编写规范,需要描述一些 JSON 对象。单独的文本和选项卡往往会使大型 JSON 变得过于困惑。是否有任何在线(最好)工具可以创建类似于 http://www.json.org/ 上的图表的工具
我正在尝试通过 DNS 将我的 Kubernetes 部署连接在一起。 我有一个 Java (Spring Boot) 部署和一个 javascript (node.js) 部署,两者都通过默认的 C
我只是在学习 WebGL 图形编程。 我正在检查包含该语句的某人的代码 // multiply the position by the matrix. gl_Position = vec4((u_ma
我是一名优秀的程序员,十分优秀!