为什么__attribute __((构造函数))在使用clang时无法在我的代码中工作但在使用其他C编译器时工作正常?

时间:2018-06-05 10:36:26

标签: c constructor clang destructor llvm-clang

当我在mingw64编译器中运行以下代码时,它工作正常,输出显示三行预期。但是当使用clang运行相同的代码时,构造函数和析构函数不能按预期工作,并且输出只是一行用main()编写的。 这是我的代码:

#include <stdio.h>

void before_main(void) __attribute__((constructor));
void after_main (void) __attribute__((destructor));

int main (void)
{
  printf ("\nInside main ()");
}

void before_main(void)
{
  printf ("\nBefore main()");
}

void after_main(void)
{
  printf ("\nAfter main()\n");
}

注意:在任何一种情况下都不会显示编译错误。该程序运行没有任何错误。

0 个答案:

没有答案