@ak16 Yes there is many uses i can think of but here is just 3 of 'em:
Safe Guards
You every got the issue where you
#include <CFOO>
8 different times and get a error? Its gonna be hard to start counting howmainy times you include ______! VS2012 got the
#pragma once
to avoid that but what happens if ya ain't got VS2012? Simple you make your own "
#pragma once
" like this :
1 2 3 4 5
|
#ifndef CFOO_HEADER_OF_AWSOMNESS
#define CFOO_HEADER_OF_AWSOMNESS
// Your CFOO_HEADER_OF_AWSOMNESS CODE
#endif
|
Whats Your OS?
Did you murder someone lately? Yes! You say its allowed on mars? But you ain't on mars!...You want to run WinAPI on mac? Yes! You say its allowed on Windows? but you ain't using windows!...
Macros
ARE VERY IMPORTANT to know what works and what doesn't....
Are you familiar with SFML? here is i piece of its code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#if defined(_WIN32)
// Windows
#define SFML_SYSTEM_WINDOWS
#ifndef NOMINMAX
#define NOMINMAX
#endif
#elif defined(__APPLE__) && defined(__MACH__)
// Apple platform, see which one it is
#include "TargetConditionals.h"
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
// iOS
#define SFML_SYSTEM_IOS
#elif TARGET_OS_MAC
// MacOS
#define SFML_SYSTEM_MACOS
#else
// Unsupported Apple system
#error This Apple operating system is not supported by SFML library
#endif
#elif defined(__unix__)
// UNIX system, see which one it is
#if defined(__ANDROID__)
// Android
#define SFML_SYSTEM_ANDROID
#elif defined(__linux__)
// Linux
#define SFML_SYSTEM_LINUX
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
// FreeBSD
#define SFML_SYSTEM_FREEBSD
#else
// Unsupported UNIX system
#error This UNIX operating system is not supported by SFML library
#endif
#else
// Unsupported system
#error This operating system is not supported by SFML library
#endif
|
Acording to SFML when you got ________, C++ defines _________.
Windows -
_WIN32
Apple -
__APPLE__
and
__MACH__
Apple IOS -
TARGET_OS_IPHONE
or
TARGET_IPHONE_SIMULATOR
Apple MacOS -
TARGET_OS_MAC
Unix -
__unix__
Unix Android -
__ANDROID__
Unix Linux -
__linux__
Unix FreBSD -
__FreeBSD__
or
__FreeBSD_kernel__
Maxing stuff Shorter....
Do you seriously want to memorize this? :
std::numeric_limits<int>::max();
when you could just do this
#define Infinity std::numeric_limits<int>::max();
and start placing
everywhere