char(* ptr)[] [英] char (*ptr)[]
问题描述
这种宣言意味着什么:
void f(char(* ptr)[]);
这是一样的
void f(char ** ptr);
与否?
Rafal
-
sed -es / s / a / g< my_address> my_right_address
What does mean such declaration:
void f( char (*ptr)[] );
Is this the same as
void f( char **ptr );
or not ?
Rafal
--
sed -e s/s/a/g <my_address >my_right_address
推荐答案
In文章< cv ********** @ atlantis.news.tpi.pl>,
Rafal Dabrowa< rd ****** @ poczts.onet.pl>写道:
:这样的声明是什么意思:
:void f(char(* ptr)[]);
:这是和
:void f(char ** ptr);
:或不是?
第一个,有向读者暗示,指向的是一个
常量指针 - 而不是指向你可能正在更新的指示
a指针的情况。
我不记得语义上是否有任何差异;我肯定
有人会插话;-)
-
沃霍尔的第二使用网法:在未来,每个人都会在15分钟内哄骗
。
In article <cv**********@atlantis.news.tpi.pl>,
Rafal Dabrowa <rd******@poczts.onet.pl> wrote:
:What does mean such declaration:
: void f( char (*ptr)[] );
:Is this the same as
: void f( char **ptr );
:or not ?
In the first, there is a hint to the reader that what is pointed to is a
constant pointer -- instead of it being the case that you are pointing to
a pointer that you might be updating.
I do not recall whether there is any difference semantically; I''m sure
someone will chime in ;-)
--
Warhol''s Second Law of Usenet: "In the future, everyone will troll
for 15 minutes."
Rafal Dabrowa写道:
Rafal Dabrowa wrote:
什么意思是这样的宣言:
void f(char(* ptr)[]);
这是一样的
void f (char ** ptr);
是不是?
What does mean such declaration:
void f( char (*ptr)[] );
Is this the same as
void f( char **ptr );
or not ?
它们不一样。
void f (char(* ptr)[]);
声明一个函数f,它接受一个参数,这个参数是一个指针
到一个char数组,并且没有返回值。
void f(char ** ptr);
声明一个函数f,它接受一个指针
指向char的指针,并且不返回任何值。
指针不是数组。
They are not the same.
void f(char (*ptr)[]);
declares a function f that takes an argument which is a pointer
to an array of char, and that returns no value.
void f(char **ptr);
declares a function f that takes an argument which is a pointer
to a pointer to char, and that returns no value.
Pointers are not arrays.
Rafal Dabrowa写道:
Rafal Dabrowa wrote:
什么是mea这样的声明:
void f(char(* ptr)[]);
您的编译器是否接受此声明?我认为
尺寸是必需的。
这是一样的
void f(char ** ptr);
是不是?
拉法尔
-
sed -es / s / a / g< my_address> my_right_address
What does mean such declaration:
void f( char (*ptr)[] );
Does your compiler accept this declaration? I would think the
dimension is required.
Is this the same as
void f( char **ptr );
or not ?
Rafal
--
sed -e s/s/a/g <my_address >my_right_address
他们非常不同。第一个ptr,指向一个完整的数组,所以如果
u做指针算术(比如ptr ++),你就跳过数组的总大小
你的情况。第二个ptr指向一个
指针,该指针又指向一个数组。所以做一些像
ptr ++会增加sizeof(char *)。
They are very different. The first ptr, points to a whole array, so if
u do pointer arithmetic (like ptr++), you step over the total size of
the array, which is missing in your case. The second ptr, points to a
pointer, which in turn points to an array. So doing something like
ptr++ would increment by the sizeof(char *).
这篇关于char(* ptr)[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!