它们是等价的吗? [英] Are they equivalent ?
问题描述
我有一定的情况,特定的代码片段在
特定编译器上工作,但在另一个专有编译器上失败。似乎
已经修复,但我只想确认两个陈述是否相似
类似:
*((char **)v)+ + == *((char **)v ++)
其中v是指向字符数组的指针,定义为
char * v [] ;
我正在传递v期待一个char *的功能。
为无法提供最低限度的可编程程序而道歉。
Tx
~
Hi,
I have a certain situation where a particular piece of code works on a
particular compiler but fails on another proprietary compiler.It seems
to have been fixed but I just want to confirm if both statements are
similar :
*((char **)v)++ == *((char **)v++)
Where v is a pointer to an array of characters,defined as
char *v[];
I am passing "v" to a function expecting a char * .
Apologize for not being able to provide a minimum compilable program.
Tx
~
推荐答案
grid写道:
我有一定的特定代码片段在特定编译器上运行但在另一个专有编译器上失败的情况。似乎已经修复但我只想确认两个语句是否相似:
*((char **)v)++ == *((char **)v ++)
Hi,
I have a certain situation where a particular piece of code works on a
particular compiler but fails on another proprietary compiler.It seems
to have been fixed but I just want to confirm if both statements are
similar :
*((char **)v)++ == *((char **)v++)
[...]
不,他们不相似。
*((char **)v)++
取消引用v和后递增它指向的内容。
*((char **)v ++)
后递增v本身,然后取消引用它。
-
+ ---------------------- --- + -------------------- + ------------------------- ---- +
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody / at\spamcop.net | www.fptech.com | #include< std_disclaimer.h> |
+ ------------------------- + -------------- ------ + ----------------------------- +
不要给我发电子邮件:< mailto:Th ************* @ gmail.com>
[...]
No, they are not similar.
*((char **)v)++
Dereferences v and post-increments what it points to.
*((char **)v++)
Post-increments v itself, and then dereferences it.
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don''t e-mail me at: <mailto:Th*************@gmail.com>
>
Kenneth Brody在12月13日10:46写道:
Kenneth Brody wrote On 12/13/05 10:46,:
grid写道:
grid wrote:
*((char **)v)++ == *((char **)v ++)
[...]
不,它们不相似。
Hi,
I have a certain situation where a particular piece of code works on a
particular compiler but fails on another proprietary compiler.It seems
to have been fixed but I just want to confirm if both statements are
similar :
*((char **)v)++ == *((char **)v++)
[...]
No, they are not similar.
到目前为止。
*((char **)v)++
取消引用v和后递增它指向的内容。
否;这个是违反约束的。从语法上讲,
它要求将'v''的值转换为'char **''类型,
然后将该值转换为后递增,同时
取消引用未递增的值。约束
违规是尝试后递增表达式
`((char **)v)'',这不是左值。
*((char **)v ++)
后递增v本身,然后取消引用它。
Right so far.
*((char **)v)++
Dereferences v and post-increments what it points to.
No; this one''s a constraint violation. Syntactically,
it asks for the value of `v'' to be converted to type `char**'',
then for that value to be post-incremented, meanwhile
dereferencing the non-incremented value. The constraint
violation is the attempt to post-increment the expression
`((char**)v)'', which is not an lvalue.
*((char **)v++)
Post-increments v itself, and then dereferences it.
对。注意,它是指它。指的是'v''转换后的
值,就像它在递增之前一样。
-
呃********* @ sun.com
Right. Note that the "it" refers to the converted
value of `v'' as it was before being incremented.
--
Er*********@sun.com
grid写道:
我有一定的情况,特定的代码片段在特定的编译器上运行但在另一个专有编译器上失败。它似乎<已修复但我只想确认两个陈述是否相似:
*((char **)v)++ == *((char **) )v ++)
其中v是指向字符数组的指针,定义为
char * v [];
Hi,
I have a certain situation where a particular piece of code works on a
particular compiler but fails on another proprietary compiler.It seems
to have been fixed but I just want to confirm if both statements are
similar :
*((char **)v)++ == *((char **)v++)
Where v is a pointer to an array of characters,defined as
char *v[];
这些表达式不等同,如果''v''真的是一个数组类型(因为
反对char **),它们都是非法的。
" *((char **)v)++" casts''v'',postincrements it and dereferences it,这是
非法因为增量运算符的操作数可能不是一个演员
表达式(它是'不是左值。
" *((char **)v ++)" postincrements''v'',强制转换它并取消引用它,这是非法因为增量运算符的操作数可能不是数组
类型。如果''v''是char **,这将起作用,但是,特别是如果它是一个声明为char * v []的
函数参数。但在这种情况下,演员阵容是多余的,整个陈述相当于简单的* v ++
(解除引用和后增量有相同的优先权和合作伙伴
从右到左)。
目前还不清楚你的目标是什么。您可能还意味着v [0] ++,
等于(*(char **)v)++ (或简称(* v)++)。
S.
These expressions are not equivalent, and if ''v'' is truly an array type (as
opposed to a char**) they are both illegal.
"*((char **)v)++" casts ''v'', postincrements it and dereferences it, which is
illegal because the operand of the increment operator may not be a cast
expression (it''s not an lvalue).
"*((char **)v++)" postincrements ''v'', casts it and dereferences it, which is
illegal because the operand of the increment operator may not be of array
type. This will work if ''v'' is a char**, however, in particular if it''s a
function argument declared as "char *v[]". But in this case the cast is
superfluous, and the statement as a whole is equivalent to simply "*v++"
(dereferencing and postincrement have the same precedence, and associate
right-to-left).
It''s unclear what expression you''re going for. You might also mean "v[0]++",
which is equivalent to "(*(char **)v)++" (or simply "(*v)++").
S.
这篇关于它们是等价的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!