typedef和函数声明 [英] typedef and declaration of function

查看:65
本文介绍了typedef和函数声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这个问题与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

推荐答案

Vu Pham< vu@sivell.com>在comp.lang.c上潦草地写下以下

Vu Pham <vu@sivell.com> scribbled the following
on comp.lang.c:
我认为这个问题与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();


是的,有。第一个声明一个带有三个参数的函数,

类型(char *),(int)和(int *),并返回一个(void *)。

第二个声明一个函数接受一个未指定数量的

参数,并返回一个指向第一种情况下声明为

的函数的指针。

这是一个非常基本的区别。

我认为它们是相同的,但我肯定在某个地方是错的。该函数被编译并链接到.so文件中。对于第一个声明,nm(1)
在.so文件中显示该名称,但不在第二个声明中显示。


他们与所有人不一样。也许这就是为什么你得到了不同的结果



注意.so文件和nm(1)在这里是偏离主题的。

这些声明中的每一个都被外部C包含在内。 {}。实现
文件是一个用g ++编译的.cpp。
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();
Yes, there is. The first declares a function taking three arguments,
of types (char *), (int) and (int *), and returning a (void *).
The second declares a function taking an unspecified number of
arguments, and returning a pointer to a function that is declared as
in the first case.
That''s a pretty fundamental difference.
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.
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.
Each of these declaration is embraced by extern "C" { }. The implenetation
file is a .cpp compiled with g++.




这就是C ++,这里也是偏离主题的。但我可以说

与我上面所说的相同,适用于C ++,但有一点不同:替换

未指定数量的参数 没有参数。


-

/ - Joona Palaste(pa*****@cc.helsinki.fi) - -----------芬兰-------- \

\-- http://www.helsinki.fi/~palaste ---------------------规则! -------- /

"''我'是世界上最美丽的词。"

- 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


Joona I Palaste< pa ***** @ cc.helsinki.fi>在comp.lang.c上潦草地写下以下

Joona I Palaste <pa*****@cc.helsinki.fi> scribbled the following
on comp.lang.c:
Vu Pham< vu@sivell.com>在comp.lang.c上潦草地写下以下内容:
Vu Pham <vu@sivell.com> scribbled the following
on comp.lang.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文件中显示该名称,但不在第二个声明中显示。
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.


它们与所有名称不同。也许这就是为什么你得到不同的结果。
请注意.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)--- ----------芬兰-------- \

\-- http://www.helsinki.fi/~palaste --------------------- 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


Vu Pham写道:
Vu Pham wrote:
我认为这个问题与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文件中显示该名称,但不在第二个声明中显示。

这些声明中的每一个都被externC包含。 {}。实现
文件是用.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




这与以下两者之间的区别相同:


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和函数声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆