Michael C. Toren on 26 Apr 2004 21:08:02 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] #define for 32 vs 64 bit C program?


On Mon, Apr 26, 2004 at 04:43:31PM -0400, Walt Mankowski wrote:
> I have a C app that was developed on a 32 bit Linux box, and I'm
> trying to get it to compile cleanly on a 64 bit opteron.  Does anyone
> know of a gcc preprocessor directive that will tell whether a source
> file is being compiled for 32 or 64 bits?

[..]

> But I'm pretty sure that "__32_BITS__" isn't the right directive.
> Does anyone know what the recommended way to do this is?

Looking through /usr/include on a Debian system, it appears that if you
include <bits/wordsize.h> you'll have access to __WORDSIZE.  I've never
had a need to use it, though, and I have no idea how portable it is.

I don't have access to a 64bit machine to test, but would it be possible
to check the sizeof an int?  Perhaps something along the lines of:

	int i;

	if (sizeof i * 8 == 64) {
		// ...
	}

-mct
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug