Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: win32 or win64



Permlink Replies: 3 - Last Post: Feb 14, 2017 3:44 PM Last Post By: Arkady Semylio
Asger Joergensen

Posts: 370
Registered: 11/18/08
win32 or win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 14, 2017 2:48 PM
Hi

#ifdef __WIN32__
bool win32 = true;
#else
bool win32 = false;
#endif


Is that an ok way to know if the code is compiling for 32 or 64 bit ?

it seem to work.;-)

Thanks in advance
Best regards
Asger
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: win32 or win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 14, 2017 3:19 PM   in response to: Asger Joergensen in response to: Asger Joergensen
Asger wrote:

Is that an ok way to know if the code is compiling for 32 or 64 bit ?

Yes, or alternatively:

#ifndef _WIN64
bool win32 = true;
#else
bool win32 = false;
#endif


Alternatively:

#if defined(_WIN32) && !defined(_WIN64)
bool win32 = true;
#else
bool win32 = false;
#endif


Watch out that the Win32 SDK defines _WIN32 for both 32bit and 64bit.
__WIN32__ should be safe, though.

Remember to wrap that in an '#ifdef _Windows' statement if you are compiling
for multiple platforms:

#ifdef _Windows
bool win32 = ...;
#endif


Or:

#if defined(_WIN32) || defined(_WIN64)
bool win32 = ...;
#endif


If you just want to detect 32bit vs 64bit regardless of platform, you could
use sizeof() instead:

bool is32bit = (sizeof(void*) == 4);
bool is64bit = (sizeof(void*) == 8);


Though, it doesn't make much sense to use runtime variables to detect Win32
vs Win64, 32bit vs 64bit, etc in the first place.

--
Remy Lebeau (TeamB)
Asger Joergensen

Posts: 370
Registered: 11/18/08
Re: win32 or win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 14, 2017 3:29 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi Remy

Thanks for explaining

Best regards
Asger
Arkady Semylio

Posts: 87
Registered: 9/18/15
Re: win32 or win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 14, 2017 3:44 PM   in response to: Asger Joergensen in response to: Asger Joergensen
Asger Joergensen wrote:
Hi

it seem to work.;-)

Possibly, to also discriminate the compiler technology, if needed:

  #if defined(__clang__)
    #if defined(_WIN64)  
      // BCC64
      bool win32 = false;
    #else  
      // BCC32C
      bool win32 = true;
    #endif
  #else 
      // BCC32
      bool win32 = true;
  #endif


Bye bye
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02