문제

I want to move a pointer forward one byte. But I get this error:

lvalue required as increment operand

With this code:

int **test = 0;
((char *) *test)++;

But it is fine with this:

int **test = 0;
char **t2 = (char **) test;
(*t2)++;

How do I do the latter concisely?

도움이 되었습니까?

해결책 2

Try to use

(*(char **)test)++;

다른 팁

If you want to increment the value pointed to by a double pointer:

(* (char **) test)++;

which means de-refrence the double pointer named "test" and then increment the value it is currently pointing to.

That will increment the value the pointer is pointing too, not advance the pointer itself. That's what I think you are trying to do in your sample code.

Contrary to the accepted answer, I believe the only way to do this is:

int **test = 0;
test = (int **)((char *)test + 1);

Any expression with a dereference *, such as (*(char **)test)++, while it may compile will generally give a segmentation fault, because it is accessing memory location 0.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top