问题描述
我认为这个问题与c或c ++有关(但我不确定哪个是
)所以我发布到这两个新闻组。我很抱歉,如果我做了什么
错了。
这两个声明之间有什么区别:
1.
void * functionA(char * p,int s,int * e);
和
2。
typedef void *(* functionA_t)(char * p,int s,int * e);
functionA_t functionA();
我以为他们是一样的,但我在某处肯定是错的。该函数被编译并链接到.so文件中。
。对于第一个声明,nm(1)
在.so文件中显示该名称,但不在第二个声明中显示。
这些声明中的每一个都是被外部C所接受{}。实现
文件是一个用g ++编译的.cpp。
谢谢,
Vu
I think this problem relates to either c or c++ ( but I am not sure which
one ) so I post to both of these news group. I am sorry if I did something
wrong here.
Is there any difference between these two declarations :
1.
void * functionA( char * p, int s, int * e );
and
2.
typedef void * ( *functionA_t)( char * p, int s, int * e );
functionA_t functionA();
I thought they are the same, but I must be wrong somewhere. The function is
compiled and linked into a .so file. For the first declarartion, nm(1)
shows that name in the .so file, but not for the 2nd declaration.
Each of these declaration is embraced by extern "C" { }. The implenetation
file is a .cpp compiled with g++.
Thanks,
Vu
推荐答案
这就是C ++,这里也是偏离主题的。但我可以说
与我上面所说的相同,适用于C ++,但有一点不同:替换
未指定数量的参数 没有参数。
-
/ - Joona Palaste(pa*****@cc.helsinki.fi) - -----------芬兰-------- \
\-- ---------------------规则! -------- /
"''我'是世界上最美丽的词。"
- John Nordberg
This smacks of C++, which is also off-topic here. But I can say that
the same I said above applies for C++, with one difference: replace
"an unspecified number of arguments" with "no arguments".
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"''I'' is the most beautiful word in the world."
- John Nordberg
它们与所有名称不同。也许这就是为什么你得到不同的结果。
请注意.so文件和nm(1)在这里是偏离主题的。
They are not the same as all. Maybe that''s why you are getting
different results.
Note that .so files and nm(1) are off-topic here.
我的意思是完全不一样。抱歉这个令人困惑的错字。
-
/ - Joona Palaste(pa*****@cc.helsinki.fi)--- ----------芬兰-------- \
\-- --------------------- rules ! -------- /
" C ++。 C ++运行。运行,++,运行。"
- JIPsoft
I meant "not the same at all". Sorry for the confusing typo.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"C++. C++ run. Run, ++, run."
- JIPsoft
这与以下两者之间的区别相同:
extern int a;
和
int * a;
第一个是整数的声明。
第二个定义了一个指向int类型的变量。
在你的第一个例子中,functionA声明一个函数
返回void *,取char *,int和int *
在你的第二个例子中functionA是一个返回功能的指针
void *,取char *,int和int *
这有什么意义吗?
It''s the same as the difference between:
extern int a;
and
int *a;
The first one is a declaration of an integer.
The second one defines a variable of type pointer to int.
In your first example, functionA the declaration of a function
returning void*, taking char *, int, and int*
In your second example functionA is a POINTER TO A FUNCTION returning
void*, taking char *, int, and int*
Does that make some sense?
这篇关于typedef和函数声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!