Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting 64bit compile in C

Tags:

c

linux

unix

gcc

is there a C macro or some kind of way that i can check if my c program was compiled as 64bit or 32bit at compile time in C?

Compiler: GCC Operating systems that i need to do the checks on: Unix/Linux

Also how could i check when running my program if the OS is capable of 64bit?

like image 648
Daniel Avatar asked Mar 11 '11 12:03

Daniel


People also ask

How can I tell if GCC is 32 or 64-bit?

To check this, we have to type this command. gcc –v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu ........... ........... ...........

How do I compile 64-bit GCC?

Just type the following command on Linux terminal. Command: gcc -v Output Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper Target: x86_64-linux-gnu ...................... ......................

What is 64-bit compiler?

After you convert your 32-bit driver source code to use the new data types, you can use the 64-bit compiler to identify any type-related problems that you initially missed. The first time you compile this code for 64-bit Windows, the compiler might generate many pointer-truncation or type-mismatch warnings.

How do I compile 32-bit Ubuntu 64-bit?

Firstly, we need GCC, the GNU compiler collection. Secondly, binutils is a set of tools for creating and managing binary programs, including a linker and assembler. In addition, we have to install Make – the build automation tool – and the C standard library glibc.


2 Answers

Since you tagged this "gcc", try

#if __x86_64__ /* 64-bit */ #endif 
like image 63
Anomie Avatar answered Oct 05 '22 04:10

Anomie


Here is the correct and portable test which does not assume x86 or anything else:

#include <stdint.h> #if UINTPTR_MAX == 0xffffffff /* 32-bit */ #elif UINTPTR_MAX == 0xffffffffffffffff /* 64-bit */ #else /* wtf */ #endif 
like image 44
R.. GitHub STOP HELPING ICE Avatar answered Oct 05 '22 05:10

R.. GitHub STOP HELPING ICE