-2

I have some operation like this C++ code that I want to convert in C89:

return reinterpret_cast<uint8_t *>(stream.buffer) - buffer;

How can I replace the reinterpret cast in C?

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
richerarc
  • 250
  • 1
  • 8

2 Answers2

3

Nothing very exciting, you've seen this before:

(uint8_t *)(stream.buffer)

That's the only way to cast something in C.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148
  • so the reinterpret cast do really nothing more that a "classic" cast? – richerarc Jul 12 '16 at 12:36
  • 3
    Pretty much. C++ has other kinds of casts that C does not have. However it's not exactly a one-to-one match. `reinterpret_cast` does not do what a C-style cast does for casting to a subclass. – Sam Varshavchik Jul 12 '16 at 12:37
3

You could simply use a C style cast:

(uint8_t*)stream.buffer
Wum
  • 306
  • 1
  • 10