简体   繁体   English

C中没有复合语句的函数定义

[英]Function definition without compound statement in C

I am confused by the following function definition without a compound statement in C:我对以下没有 C 复合语句的函数定义感到困惑:

void
__tu_finishme(const char *file, int line, const char *format, ...)
   tu_printflike(3, 4);

It seems to not result in a function in generated object files, while the linker still expects __tu_finishme to have been written.它似乎不会在生成的目标文件中产生一个函数,而链接器仍然希望__tu_finishme已经被写入。 Especially odd to me since对我来说特别奇怪,因为

void
__tu_finishme(const char *file, int line, const char *format, ...) {
   tu_printflike(3, 4);
}

seems to have different (AKA "normal") linkage than the former.似乎与前者有不同的(又名“正常”)联系。

Can someone please explain which concept and niche of the C language I encounter here and how it works?有人可以解释一下我在这里遇到的 C 语言的哪个概念和利基以及它是如何工作的吗?

Bonus points for explaining things like:解释以下内容的奖励积分:

void
foo(const char* c)
   bar()
{
    ha = hoo();
    boo(ha);
}

tu_printflike is very likely a macro that expands to an attribute like : tu_printflike很可能是一个扩展为属性例如

__attribute__ ((format (printf, 3, 4)))

The above is GCC specific, so the use of a macro is there to enable portability across compilers, it can be defined as something akin to以上是特定于 GCC 的,因此使用宏是为了实现跨编译器的可移植性,它可以定义为类似于

#ifdef __GNUC__
#  define tu_printflike(i, j) __attribute__ ((format (printf, i, j)))
#else
#  define tu_printflike(i, j) 
#endif

Your bonus point can be explained just the same with您的奖励积分可以用同样的方式解释

#define bar()

Where the definition is just an empty token sequence, the function like macro expands to nothing.在定义只是一个空的标记序列的情况下,像宏这样的函数扩展为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM