News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Pointer arithmetic - casting pointer to other type

Started by Mr.Madguy, May 22, 2023, 08:23:03 PM

Previous topic - Next topic

Mr.Madguy

I'm new to C++ and this language seems to be a little bit vague for me.

Please explain, for what reason I should use such code

void* Src;
{
  t* TempSrc = (t*)Src;
  ...
  TempSrc++;
  ...
  Src = (void*)TempSrc;
};

instead of just

  void* Src;
  (t*)Src++;

?

In second case compiler complains about incrementing void pointer, so I assume, that pointer casting doesn't work. And in case of ((t*)Src)++ compiler complains about lvalue.
Is it healthy for project not to have regular stable releases?

Miguel Gimenez


Mr.Madguy

Ok, seems to be fixed via following trick:

Src = (void*)((t*)Src + 1);
Is it healthy for project not to have regular stable releases?