GCC:在C99允许重载函数 [英] GCC: Allow overloaded functions in C99

查看:442
本文介绍了GCC:在C99允许重载函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的C99 code,并通过GCC编译。我想用函数重载为文体的原因(否则我会做的名字由我自己重整)。

I write code in C99 and compile via GCC. I would like to use function overloading for stylistic reasons (otherwise I would have to do name mangling by myself).

我读<一个href=\"http://stackoverflow.com/questions/1314613/is-there-a-reason-that-c99-doesnt-support-function-overloading\">Is但有一个原因,C99不支持函数重载?的,我仍然不知道它是否能在GCC被启用。

I have read Is there a reason that C99 doesn't support function overloading? however, I still wonder whether it can be enabled in GCC.

你能帮我在这一点上?

推荐答案

没有,没有功能的C99重载,甚至在无聊的GCC扩展。 C11增加了 _Generic ,但即便如此,你还是要自己裂伤名。

No, there is no function overloading in C99, not even in silly GCC extensions. C11 adds _Generic, but even then you still have to mangle names yourself.

void foo_int(int x);
void foo_double(double x);

#define foo(arg) _Generic((arg), int: foo_int, double: foo_double)(arg)

这是否是好还是坏,好。它的温度。

Whether that's better or worse, well. It's C.

这篇关于GCC:在C99允许重载函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆