PureBasic Compiler-specific extensions in C++

PureBasic is a high-level programming language that utilizes its own compiler to generate efficient machine code. While primarily designed for use with PureBasic, the compiler also provides a set of extensions that can be used in C++ to access PureBasic features.

In this blog post, we will explore some of the PureBasic compiler-specific extensions available in C++ and discuss their usage and benefits.

1. PUB_EXTERN and PUB_FUNC

PureBasic functions can be declared in C++ using the PUB_EXTERN and PUB_FUNC macros. These macros allow you to define and call PureBasic functions from your C++ code.

Example:

#include "PureBasic.h"

PUB_EXTERN(int64_t, MyPureBasicFunction)(int32_t argument);

int main() {
    int32_t argument = 42;
    int64_t result = MyPureBasicFunction(argument);
    
    // Use the PureBasic function result
    // ...
    
    return 0;
}

In the above example, the PUB_EXTERN macro is used to declare a PureBasic function named MyPureBasicFunction in C++. The function takes an int32_t argument and returns an int64_t value. The function is then called from the main C++ function.

2. PB_EXTERN_C

The PB_EXTERN_C macro is used to indicate that a block of C++ code should be treated as PureBasic code when compiling with the PureBasic compiler.

Example:

#include "PureBasic.h"

PB_EXTERN_C {
  void MyPureBasicRoutine() {
    // PureBasic code goes here
    // ...
  }
}

int main() {
  MyPureBasicRoutine();
  
  // Continue C++ code execution
  // ...
  
  return 0;
}

In the above example, the PB_EXTERN_C macro is used to define a PureBasic routine named MyPureBasicRoutine. The code block within the PB_EXTERN_C macro is treated as PureBasic code by the PureBasic compiler.

These are just a few examples of the PureBasic compiler-specific extensions available in C++. Incorporating these extensions in your C++ code allows you to leverage the features and capabilities of PureBasic in your projects, resulting in fast and efficient code execution.

Discover the power of PureBasic’s compiler-specific extensions in your C++ projects today!

#PureBasic #C++