空洞增量* [英] increment of void *
问题描述
我心中有些困惑
void * search_address = 0;
[某事......]
++ search_address;
/ *编译器抱怨void *是未知的大小。
好的,我更改了代码
* /
void * search_address = 0;
[东西......]
++(字符*)search_address;
我尝试将其转换为char *在增量之前,这是非法的吗?
提前致谢。
-
BC
I have something confused in my mind
void *search_address = 0;
[something...]
++search_address;
/* The compiler complain that "void *" is unknown size.
OK, I changed the code
*/
void *search_address = 0;
[something...]
++(char*)search_address;
I try to cast it to char* before the increment, is it illegal here ?
Thanks in advance.
--
BC
推荐答案
Burne C写道:
Burne C wrote:
++(char *)search_address;
我试着在增量之前将它转换为char *,这在这里是非法的吗?
++(char*)search_address;
I try to cast it to char* before the increment, is it illegal here ?
是的。强制转换的结果是(临时)值而不是
对象,因此++运算符不能应用于它。
Jeremy。
Yes. The result of a cast is a ("temporary") value rather than an
object, so the ++ operator can''t be applied to it.
Jeremy.
2003年7月26日星期六17:08:07 +0800,Burne C < a@b.com>写道:
On Sat, 26 Jul 2003 17:08:07 +0800, "Burne C" <a@b.com> wrote:
我心中有些困惑
[snip]
void * search_address = 0;
[东西......]
++(char *)search_address;
我尝试在增量之前将其强制转换为char *这是不合法的吗?
I have something confused in my mind
[snip]
void *search_address = 0;
[something...]
++(char*)search_address;
I try to cast it to char* before the increment, is it illegal here ?
不会因为那相当于
(char *)search_address =(char *)search_address + 1;
ANSI C不允许施放左值。
这将起作用:
search_address =(char *)search_address + 1;
尼克。
No. Because that''s equivalent to
(char *)search_address = (char *)search_address + 1;
ANSI C does not allow an lvalue to be cast.
This will work:
search_address = (char *)search_address + 1;
Nick.
> ANSI C不允许转换左值。
> ANSI C does not allow an lvalue to be cast.
这将起作用:
search_address =(char *)search_address + 1;
This will work:
search_address = (char *)search_address + 1;
作为回应:这个演员也是非法的吗?
/ * ul是无符号长整理,包含指向字符串的指针* /
if((char *)ul == NULL)
因为虽然我对两者都感到满意,但我不确定是否使用
或
if(ul ==(long)NULL)
谢谢,
-
Martijn Haak
http://www.serenceconcepts.nl
这篇关于空洞增量*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!