🕹️
Game Engine. hardCORE series
Udemy course / C++PatreonBoostyTelegramYouTube
  • 💻Lectures
    • 00. Promo
    • 01. What is game engine?
    • 02. C++ build process. Preprocessing
      • Preprocessor commands
      • Code
    • 03. C++ build process. Compilation Theory. Assembly
      • Compiler commands
      • Code
    • 04. C++ build process. Compiler optimizations
      • Compiler commands
      • Code
    • 05. C++ build process. Linker. Forward declaration
      • Compiler commands
      • Code
    • 06. C++ build process. Linker. Static and Dynamic libraries. PCH
      • Compiler commands
      • Code
      • Books
    • 07. СMAKE. Day1. Basics
      • CMAKE commands
      • Repository
    • 08. СMAKE. Day2. Libs
      • CMAKE commands
      • Repository
    • 09. Conan. C++ package manager
      • Conan commands
      • Repository
    • 10. Raylib. CMAKE additional topics
      • Repository
    • 11. Doodle Jump Game. Raylib. CMAKE pch and other topics
      • Repository
    • 12. Conan and CMAKE integration. Github workflows
      • Commands
      • Repository
    • 13. Engine. Layout
    • 14. Engine. Logging
    • 15. Engine. Window
    • 16. Engine. Window events. Input
  • Мои курсы
    • 🎮Unreal Engine — полное руководство по разработке на С++
    • 🧪Автоматизация и тестирование в Unreal Engine
    • 🔊Metasounds
    • 🏗️Design patterns
    • 🐍Snake game
    • 🧠OpenAI
  • LifeEXE сообщество
    • Ресурсы
Powered by GitBook
On this page
  1. Lectures
  2. 04. C++ build process. Compiler optimizations

Code

#include <limits>

extern int x;
extern int y;

__forceinline int max(int x, int y)
{
    return x > y ? x : y;
}

[[msvc::forceinline]] void complexCalculation(int x)
{
    static int counter = 0;
    ++counter;

    for (int i = 1; i < 100000000; ++i)
    {
       counter *= i * x;      
       counter %= 123456789 * i;
    }
}

using FC_TYPE = long long;

constexpr FC_TYPE factorial(FC_TYPE n)
{
    return n <= 1 ? 1 : n * factorial(n-1);
}

constexpr int sum(int n)
{
   return n <= 0 ? 0 : n + sum(n-1);
}

class Point
{
public:
     constexpr Point(int x, int y): m_x(x), m_y(y) {}
     
private:
    const int m_x;
    const int m_y;
};

constexpr Point c_point = Point(10, 20);

// #pragma optimize( "", off )
int main() 
{
    const auto result1 = max(89, 45);
    constexpr auto result2 = factorial(10);
    constexpr auto result3 = sum(100);
    complexCalculation(5);
    constexpr auto intMax = std::numeric_limits<FC_TYPE>().max(); 
}
// #pragma optimize( "", on )

#include <iostream>

#define FPS_DATA alignas(4)

// #pragma pack(push, 4)
struct FPS_DATA Ammo
{
    bool empty;
    char padding1[2];
    int bullets;
    bool taken;
    char padding2[3];
};
// #pragma pack(pop)
static_assert(sizeof(struct Ammo) == 12, "Struct layout was changed");

int main() 
{
    std::cout << "Size of Ammo: " << sizeof(Ammo) << std::endl;
    std::cout << "Align of Ammo: " << alignof(Ammo) << std::endl;
}
PreviousCompiler commandsNext05. C++ build process. Linker. Forward declaration

Last updated 10 months ago

💻