将指针数组传递给函数 [英] Passing pointer array to function
问题描述
我有一个结构:
typedef struct {
char ** user_comments;
int * comment_wds;
int comments;
char * vendor;
} vorbis_comment;
void func(char ** table)
{
返回;
}
int main(无效)
{
vorbis_comment vc;
/ *这部分海湾合作委员会不喜欢* /
func(vc.user_comments );
返回0;
}
GCC(3.1)会说
I have a struct:
typedef struct {
char **user_comments;
int *comment_wds;
int comments;
char *vendor;
} vorbis_comment;
void func (char **table)
{
return;
}
int main (void)
{
vorbis_comment vc;
/* This part GCC doesn''t like */
func (vc.user_comments);
return 0;
}
GCC (3.1) would say that
警告:从不兼容的指针类型传递''func''的arg 1
warning: passing arg 1 of ''func'' from incompatible pointer type
但我的代码仍然在''func''(未发布,上面是一个例子)正常工作,
利用整个''**表''。
现在我想问的是哪个是合法的方法拨打这个
类的电话?或者它只是一个错误或功能?海湾合作委员会?
我用命令行编译:
gcc -Wall -pedantic -ansi -mcpu = athlon -ffast-math -O2 >
推荐答案
" Tatu Portin" <斧**** @ mbnet.fi>在消息中写道
news:TE *************** @ read3.inet.fi ...
"Tatu Portin" <ax****@mbnet.fi> wrote in message
news:TE***************@read3.inet.fi...
我有一个结构:
typedef struct {
char ** user_comments;
int * comment_wds;
int comments;
char * vendor;
} vorbis_comment ;
void func(char ** table)
{
返回;
}
int main(无效)
{
vorbis_comment vc;
/ *这部分海湾合作委员会不喜欢* /
func(vc.user_comments);
>返回0;
}
GCC(3.1)会说
I have a struct:
typedef struct {
char **user_comments;
int *comment_wds;
int comments;
char *vendor;
} vorbis_comment;
void func (char **table)
{
return;
}
int main (void)
{
vorbis_comment vc;
/* This part GCC doesn''t like */
func (vc.user_comments);
return 0;
}
GCC (3.1) would say that
警告:从不兼容的指针类型传递''func''的arg 1 >但我的代码仍然在''func''(未发布,
warning: passing arg 1 of ''func'' from incompatible pointer type
But still my code in ''func'' (not posted,
为什么不呢?
以上是一个例子)正常工作,
利用整个''**表''。
现在我想问的是,这种拨打
的合法方式是什么?或者它只是一个错误或功能? GCC?
Why not?
above is an example) works correctly,
utilizing whole ''**table''.
Now what I want to ask is that which is the legal way to make a call of
this kind? Or is it just a bug or "feature" of GCC?
我们无法告诉您调用我们看不到的
定义(至少是声明)的函数的正确形式。
''func()''的签名是什么?请记住,数组不是指针,
和指针不是数组。
-Mike
We cannot tell you the correct form for calling a function whose
definition (at least declaration) that we cannot see. What is
the signature of ''func()''? Remember that an array is not a pointer,
and a pointer is not an array.
-Mike
>
Tatu Portin写道:
Tatu Portin wrote:
我有一个结构:
cat main.c
typedef struct {
char ** user_comments;
int * comment_wds;
int comments;
char * vendor;
} vorbis_comment;
void func(char ** table){
return;
}
int main(int argc,char * argv []){
vorbis_comment vc;
/ * GCC不喜欢这部分内容。 * /
func(vc.user_comments);
返回0;
}
gcc -Wall -ansi -pedantic -ffast-math -O2 -o main main.c
gcc --version
gcc(GCC)3.4.1
GCC (3.1)会说
I have a struct:
cat main.c typedef struct {
char** user_comments;
int* comment_wds;
int comments;
char* vendor;
} vorbis_comment;
void func(char** table) {
return;
}
int main(int argc, char* argv[]) {
vorbis_comment vc;
/* GCC doesn''t like this part. */
func(vc.user_comments);
return 0;
}
gcc -Wall -ansi -pedantic -ffast-math -O2 -o main main.c
gcc --version gcc (GCC) 3.4.1
GCC (3.1) would say that
>警告:从不兼容的指针类型传递''func''的arg 1
>warning: passing arg 1 of ''func'' from incompatible pointer type
似乎编译得很好。
It seems to compile just fine for me.
Tatu Portin写道:
Tatu Portin wrote:
我有一个结构:
typedef struct {
char ** user_comments;
int * comment_wds;
int comments;
char * vendor;
} vorbis_comment;
void func(char ** table)
{
返回;
}
int main(无效)
{
vorbis_comment vc;
/ *这部分GCC不喜欢* /
func(vc.user_comments);
转到0;
GCC(3.1)会说
I have a struct:
typedef struct {
char **user_comments;
int *comment_wds;
int comments;
char *vendor;
} vorbis_comment;
void func (char **table)
{
return;
}
int main (void)
{
vorbis_comment vc;
/* This part GCC doesn''t like */
func (vc.user_comments);
return 0;
}
GCC (3.1) would say that
>警告:从不兼容的指针类型传递''func''的arg 1
>warning: passing arg 1 of ''func'' from incompatible pointer type
但我的代码''func''(上面没有发布,是一个例子)正确地工作
,利用整个''** table''。
现在我想问的是,这种打电话的合法途径是什么?或者它只是一个错误或功能?海湾合作委员会?
我用命令行编译:
gcc -Wall -pedantic -ansi -mcpu = athlon -ffast-math -O2
But still my code in ''func'' (not posted, above is an example) works
correctly, utilizing whole ''**table''.
Now what I want to ask is that which is the legal way to make a call of
this kind? Or is it just a bug or "feature" of GCC?
I am compiling with a commandline:
gcc -Wall -pedantic -ansi -mcpu=athlon -ffast-math -O2
>
您的代码完全按照此处的说明,粘贴到tatu.c并编译为..
gcc -Wall -pedantic -ansi -mcpu = athlon - ffast-math -O2 tatu.c
...在这里编译没有错误。
C:\ work\c\\ clc> gcc --version
gcc.exe(GCC)3.1
Copyright(C)2002 Free Software Foundation,Inc。
-
Joe Wright mailto:jo ******** @ comcast.net
所有内容都应尽可能简单,但不能更简单。
---阿尔伯特爱因斯坦---
Your code exactly as written here, pasted to tatu.c and compiled with ..
gcc -Wall -pedantic -ansi -mcpu=athlon -ffast-math -O2 tatu.c
... compiles here without error.
C:\work\c\clc>gcc --version
gcc.exe (GCC) 3.1
Copyright (C) 2002 Free Software Foundation, Inc.
--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
这篇关于将指针数组传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!