Possible useful pointer add macro for C and C++

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,633
You probably seen this macro used in C++:

Code:
#define MACRO_PTR_ADD( P, BYTES ) \
    ((decltype( P ))(((u8 *)P) + (BYTES)))

The (non-tested) equivalent in C is:

Code:
#define MACRO_PTR_ADD( P, BYTES ) \
   ((__typeof__( P ))(((u8 *)P) + (BYTES)))
 

jonas

You can change this now in User CP.
Reaction score
64
why this is necessary is beyond me. but be aware that going out of the limits of the object is undefined behavior.
 

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,633
For one, porting a C++ code to C code is one actual case for me.
 

tom_mai78101

The Helper Connoisseur / Ex-MineCraft Host
Staff member
Reaction score
1,633
Why do you need to port the C++ code to C?
For various reasons, one of which being there's no C++ compiler for it. Only C. And because of that, all libraries uses only C, and not C++.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top