c - ANSI C 和函数重载

标签 c naming overloading

<分区>

Possible Duplicate:
function overloading in C

ANSI C 不允许函数重载(我不确定 C99)。

例如:

char  max(char  x, char  y);
short max(short x, short y);
int   max(int   x, int   y);
float max(float x, float y);

不是有效的 ANSI C 源代码。

应该使用哪种技术(或想法)来解决 ANSI C 中的函数重载问题?

注意:

一个答案是重命名函数,但是应该使用哪种模式来重命名,函数名称仍然是'good function name'

例如:

char  max1(char  x, char  y);
short max2(short x, short y);
int   max3(int   x, int   y);
float max4(float x, float y);

对于 max 函数名来说不是一个好的命名

最佳答案

例如在函数名中使用要计算的数据类型

char  max_char(char  x, char  y);
short max_short(short x, short y);
int   max_int(int   x, int   y);
float max_float(float x, float y);

关于c - ANSI C 和函数重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7833648/

相关文章:

c - 在 C 中调用 exit() 后进程会发生什么样的清理?

c - 十一2.如何忽略修饰键事件?

ruby-on-rails - Rails 保留类名称

python - 为什么为 numpy 函数选择名称 "arange"?

python - Boost Python用默认参数包装静态成员函数重载

c++ - std::async 与重载函数

c - 为什么 frexp/ldexp 的有效范围是 [0.5, 1.0)?

c - 线程安全随机数

c# - C#中的命名问题

delphi - Delphi 中重载过程出错