参数来构造函数样式函数 [英] Arguments to attribute constructor style functions
问题描述
我看过这样的代码:(基于Apple的代码) 这很奇怪,因为我读到构造函数样式函数应该是无效的。这些论据来自哪里,我可以选择这些参数是什么?这是gcc / clang的苹果电脑吗? 此代码应该与DYLD_INSERT_LIBRARIES(Linux的LD_PRELOAD)一起使用。 具有 看一段代码,你的函数 它放在路径* csu / elf-init.c中的glibc库中。 我也认为,你的参数 I've seen code like this: (Apple based code) Which is odd to be because I read that constructors style functions are supposed to be void. Where are those arguments coming from, can I choose what those parameters can be? Is this an Apple only thing for gcc/clang? This code is supposed to be used with DYLD_INSERT_LIBRARIES, (Linux's LD_PRELOAD).
Is that a special reason why it gets arguments? Functions with attribute Look at the piece of code, where your function It is placed in glibc library within path *csu/elf-init.c I also deem, that your argument 这篇关于参数来构造函数样式函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ p $ __属性__((构造函数))
void do_action(int argc,const char ** argv,const char ** envp,const char **,struct ProgramVars *)
{
//
}
这是获取参数的一个特殊原因吗?
构造函数
可以与 main
具有相同的参数。他们无法区别。 LD_PRELOAD与它没有任何共同之处。此功能主要基于glibc库(不知道其他人),并且对于所有使用glibc和支持构造函数属性的编译器都是可接受的。在Linux上它工作正常。
do_action
被调用:(size_t i = 0; i< size; i ++)
(* __ init_array_start [i])(argc, argv,envp);
struct ProgramVars *
不能被赋值,只能是 nullptr
。__attribute__((constructor))
void do_action(int argc, const char **argv, const char **envp, const char **things, struct ProgramVars *)
{
//
}
constructor
can have the same arguments as main
has. They can't differ. LD_PRELOAD has nothing common with it. This feature is heavily based on glibc library (don't know about others) and is acceptable for all compilers, that use glibc and support constructor attribute. On Linux it works fine.do_action
is called:for (size_t i = 0; i < size; i++)
(*__init_array_start [i]) (argc, argv, envp);
struct ProgramVars *
can't be assigned and can be only nullptr
.