Code

#include <iostream>

#define PI 3.1415

#define MULT(a, b) ((a) * (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))

#define MAX1(a, b) \
[&]() { \
decltype(a) _a = a; \
auto _b = b; \
return _a > _b ? _a : _b; \
}()

#define NULL 0

#define WITH_EDITOR 0
#define CONFIG 101

void f(int* ptr)
{
    std::cout << "ptr" << std::endl;
}

void f(int integer)
{
    std::cout << "integer" << std::endl;
}

int main()
{
   const double r = 10.0;
   const double circleArea = PI * r * r;

   const char* coolString = "PI value";
   const char* coolPIString = "PI value";

   const int result = MULT(10 + 9, 13);
   int max = MAX(1, 2);

   int a = 11;
   int b = 22;
   max = MAX(a++, b--);
   std::cout << max << std::endl;
   std::cout << a << std::endl;
   
   a = 11;
   b = 22;
   max = MAX1(a++, b--);
   std::cout << max << std::endl;
   std::cout << a << std::endl;

   int* ptr = NULL;
   int integer = NULL;
   f(NULL);
   f(nullptr);

   bool isEditor = false;
   #ifdef WITH_EDITOR
      isEditor = true;
   #else
      isEditor = false;
   #endif // WITH_EDITOR

   enum class Config
   {
       Debug = 0,
       Release = 1
   } config;

    #ifdef CONFIG
       #if CONFIG == 100
           config = Config::Debug;
       #elif CONFIG == 101
           config = Config::Release;
       #else
           #error "Unknown configuration"
       #endif
    #endif
}
#define STRINGIFY(TOKEN) #TOKEN
#define TO_CHAR(TOKEN) #@TOKEN

#define CONCAT_IMPL(a, b) a##b
#define CONCAT(a, b) CONCAT_IMPL(a, b)

int main()
{
    const char* name = STRINGIFY(JOHN DOE);
    char chr = TO_CHAR(J);
    
    __LINE__;
    int CONCAT(result, 1) = 10;
    result1 = 11;
    
    __LINE__;
    __FILE__;
    
    int CONCAT(result, __LINE__) = 10;
    int CONCAT(result, __LINE__) = 10;
    int CONCAT(result, __LINE__) = 10;
    int CONCAT(result, __LINE__) = 10;
    int CONCAT(result, __LINE__) = 10;
}
#include <iostream>

#define DECLARE_PROPERTY(PropertyType, PropertyName) \
private: \
    PropertyType m_##PropertyName; \
public: \
    void set##PropertyName(PropertyType value) { \
        m_##PropertyName = value; \
    } \
    PropertyType get##PropertyName() const { \
        return m_##PropertyName; \
    }

class Monster
{
    DECLARE_PROPERTY(const char*, Name)
    DECLARE_PROPERTY(float, Health)
};

int main()
{
    Monster monster;
    monster.setName("Azathoth");
    monster.setHealth(10000);
    
    std::cout << monster.getName() << std::endl;
    std::cout << monster.getHealth() << std::endl;
}
#pragma message( "Compiling started " __FILE__ )

#pragma message( "Hello")
#pragma message( "how")
#pragma message( "low")

#pragma comment( user, "Compiled on " __DATE__ " at " __TIME__ )

#define PI 3.1415

#define PREPROCESSOR_TO_STRING(x) PREPROCESSOR_TO_STRING_INNER(x)
#define PREPROCESSOR_TO_STRING_INNER(x) #x
#define WARNING_LOCATION(Line) __FILE__ "(" PREPROCESSOR_TO_STRING(Line) ")"
#define EMIT_CUSTOM_WARNING_AT_LINE(Line, Warning) \
    __pragma(message(WARNING_LOCATION(Line) ": warning C4996: " Warning))

EMIT_CUSTOM_WARNING_AT_LINE(__LINE__, "Use fooNew function instead")
void foo() {}

int main()
{
    PI;
#pragma push_macro("PI")
#pragma warning( disable : 4005 )
#define PI 32435243.1415
    PI;
#pragma pop_macro("PI")
    PI;

    foo();
    
    __LINE__;
    __FILE__;
    #line 777 "hello.cpp"
    __LINE__;
    __FILE__;
}

#pragma message( "Compiling finished " __FILE__ )

Last updated