John Ashmead on 26 Apr 2004 21:32:03 -0000


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

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


I'm not aware of such a directive, but would "sizeof(int)" work? Worst case, there is "sizeof(i)".

On Apr 26, 2004, at 4:43 PM, 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?

For example, I'd like to do something like this:

#include <stdio.h>

int main () {
        long i = 42;
#ifdef __32_BITS__
        printf("i = %d\n", i);
#else
        printf("i = %ld\n", i);
#endif
        return 0;
}

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

Thanks.

Walt



John Ashmead
Ashmead Software & Consulting, Inc.
139 Montrose Avenue
Rosemont, PA 19010-1508
(610) 527 9560
fax (610) 527 4640
john.ashmead@ashmeadsoftware.com
http://www.ashmeadsoftware.com/

___________________________________________________________________________
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