如何在C中实现泛型宏? [英] How to implement a generic macro in C?

查看:107
本文介绍了如何在C中实现泛型宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FUNC(param);

paramchar *时,调度到func_string.

当它是int时,请发送到func_int

我认为可能有解决方案,因为在编译时就知道变量类型.

I think there may be a solution to this,as variable types are known at compile time..

推荐答案

这可以通过 C1X ,但不在当前标准中.

This will be possible with C1X but not in the current standard.

它看起来像这样:

#define cbrt(X) _Generic((X), long double: cbrtl, \
                          default: cbrt, \
                          float: cbrtf)(X)

这篇关于如何在C中实现泛型宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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