[CMake] Detecting 32/64 bit systems

Yngve Inntjore Levinsen yngve.levinsen at gmail.com
Mon Feb 14 13:39:40 EST 2011


Sorry, I meant LONG actually, I was a bit tired when I wrote the mail. Perhaps I should change to VOID instead, thanks for the tip.

This was my previous code:
INCLUDE(CheckTypeSize)
CHECK_TYPE_SIZE (long LONG_SIZE) #4 if 32bit, 8 if 64bit...

I don't actually build for Windows yet, so I suppose that is why I didn't notice the potential problem...

Cheers,
Yngve


On Monday 14 February 2011 10:35:26 AM Rolf Eike Beer wrote:
> > I have done the same thing myself, using size of INT instead of P which is
> > of course following the exact same logic.
> > After attempting several strategies I found this one to be the safest way
> > to detect 32/64bit systems, so I recommend using SIZEOF as well.
> 
> sizeof(int) is 4 on basically all systems I have ever seen (ignoring those
> 16bit machines of 286 areas or things like that) so this test is basically
> useless. Also testing for sizeof(long) will get you into trouble as this 8
> for Un*x64 but 4 for Win64. The best way is usually sizeof(void*) even if
> there are programming model where you would get a 32 bit pointer even in a
> 64 bit executable but those have to be explicitely enabled and are barely
> ever used from my experience.
> 
> Eike
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
> 


More information about the CMake mailing list