数字函数的C命名约定?

时间:2012-03-21 11:07:19

标签: c naming-conventions

说我有这个功能:

int epic(int);

我知道这些命名约定,这些是对的吗?还有其他非常常见的吗?

              long epicl   (long);
         long long epicll  (long long);
      unsigned int epicu   (unsigned int);
     unsigned long epicul  (unsigned long);
unsigned long long epicull (unsigned long long);
            double fepic   (double);
             float fepicf  (float);

2 个答案:

答案 0 :(得分:1)

有时,如果返回类型与参数类型不同,则使用前缀来表示此情况。考虑以下(来自C99):


double round(double x);
float roundf(float x);
long double roundl(long double x);

long int lround(double x);
long int lroundf(float x);
long int lroundl(long double x);

long long int llround(double x);
long long int llroundf(float x);
long long int llroundl(long double x);

答案 1 :(得分:0)

嗯,你几乎总结了大部分内容。你遗忘了一些

long double fepicl(long double); /* thanks @pmg */
double epich(double); /* if epic is a hyperbolic function  */

在ARM等一些嵌入式系统中:

/* disclaimer, once saw them in an unofficial ARM SDK,
 * not sure if these conventions are standard */
u8 epic_8(u8);  
u16 epic_16(u16);