函数指针在linux和win上的一个区别
linux编译器 gcc
win编译器 vc2005
#include <stdio.h>
#include <stdlib.h>
void (*f)(int);
void (*g())(int)
{
return f;
}
#define NO_INT (void (*)())0
#define HAS_INT (void (*)(int))0
void c()
{
}
void d(int g) //win上可以不写出参数名字g,linux上必须写出,否则编译不过
{
}
int main()
{
printf("func ptr f value is :0x%x\n", (int)f);
printf("func ptr g value is :0x%x\n", (int)g);
//在windows上编译报错,提示类型不匹配
//在linux不会提示报错
//if ( g() == NO_INT)
// {
// printf("compile pass!\n");
// }
// f = c;
f = d;
if ( g() == HAS_INT)
{
printf("compile pass!\n");
}
//linux无此命令
system("pause");
}
linux编译器 gcc
win编译器 vc2005
#include <stdio.h>
#include <stdlib.h>
void (*f)(int);
void (*g())(int)
{
return f;
}
#define NO_INT (void (*)())0
#define HAS_INT (void (*)(int))0
void c()
{
}
void d(int g) //win上可以不写出参数名字g,linux上必须写出,否则编译不过
{
}
int main()
{
printf("func ptr f value is :0x%x\n", (int)f);
printf("func ptr g value is :0x%x\n", (int)g);
//在windows上编译报错,提示类型不匹配
//在linux不会提示报错
//if ( g() == NO_INT)
// {
// printf("compile pass!\n");
// }
// f = c;
f = d;
if ( g() == HAS_INT)
{
printf("compile pass!\n");
}
//linux无此命令
system("pause");
}