看x264程序中的getopt_long函数(.c文件,而非.cpp文件),看着看着,突然看到一个十分怪异的函数定义形式,查资料后才知道原来是老版本中C语言函数定义的形式. 为了简便说明,本人写个简单的示例,如下:
#include <stdio.h>
int add(x, y)
int x, y;
{
return x + y;
}
int main()
{
int a = 2;
int b = 3;
int c = add(a, b);
printf("%d\n", c);
return 0;
}
上面的程序在VC6.0的.cpp文件中有错误,但在.c文件中可以正常. 所以,上面这种形式最好废止,自己写函数时,不要写这样的,要按照新的标准来. 但如果别人这样写了,要认识.
上述程序改为:
#include <stdio.h>
int add(int x, int y)
{
return x + y;
}
int main()
{
int a = 2;
int b = 3;
int c = add(a, b);
printf("%d\n", c);
return 0;
}
最后说一句:在VC6.0中,.c文件支持老式和新式的函数定义,但.cpp文件只支持新式的函数定义. 所以,自己写函数,务必用新式的,与时俱进嘛.