Domanda

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?

È stato utile?

Soluzione 2

Try to use

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

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top