#define IS_SERVER 1
// ...
#ifdef IS_SERVER
// ... server code ...
#endif
// ...
const int isServer = 1;
// ...
if ( isServer ) {
// .. server code ...
}
// ...
#define IS_SERVER 1
// ...
#ifdef IS_SERVER
// ... server code ...
#endif
// ...
const int isServer = 1;
// ...
if ( isServer ) {
// .. server code ...
}
// ...
Quote:
Original post by Nairou
For example, will the compiler optimize the following two examples into the same thing?
#define PI 3.14156const FLOAT PI = 3.14159f;Quote:
Original post by Nairou
That got me wondering, what about things like #ifdef? For example, will the compiler optimize the following two examples into the same thing? If so, I wonder if there are any advantages of one over the other. The second seems more friendly to me, less hackish than the first.
#ifdef _WIN32 int istat = WSAStartup( ... ); #endifQuote:
Original post by SneftelFor most modern compilers, yes. To make sure of it, though, it's a good idea to force internal linkage of constants used in this way (by declaring the variable as static, or putting it in an anonymous namespace).
Quote:
To make sure of it, though, it's a good idea to force internal linkage of constants used in this way (by declaring the variable as static, or putting it in an anonymous namespace).
Quote:
Simply putting it in an anonymous namespace forces external linkage.
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more