Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a C compiler generate an executable 64-bits where pointers are 32-bits?

Most programs fits well on <4GB address space but needs to use new features just available on x64 architecture.

Are there compilers/platforms where I can use x64 registers and specific instructions but preserving 32-bits pointers to save memory?

Is it possible do that transparently on legacy code? What switch to do that?

OR

What changes on code is it necessary to get 64-bits features while keep 32-bits pointers?

like image 541
Maniero Avatar asked Nov 07 '10 08:11

Maniero


People also ask

How to compile 32-bit program on 64-bit gcc in C?

Now in order to compile with 32-bit gcc, just add a flag -m32 in the command line of compiling the 'C' language program. For instance, to compile a file of geek. c through Linux terminal, you must write the following command with -m32 flag. After that you will be able to compile a 32-bit binary on a 64-bit system.

Are pointers 64 bits?

In 64-bit data models, pointer sizes are always 64 bits.

Is gcc 32 or 64-bit?

Compile 32-bit program on 64-bit gcc in C and C++Nowadays the compiler comes with default 64-bit version. Sometimes we need to compile and execute a code into some 32bit system. In that time, we have to use thisS feature. At first, we Shave to check the current target version of the gcc compiler.

What is a 32-bit compiler?

the 32bit compiler can compile into 32bit machine code which can be run only on 32bit and 64bit microprocessor. But not less than 32 bit. Follow this answer to receive notifications.


1 Answers

A simple way to circumvent this is if you'd have only few types for your structures that you are pointing to. Then you could just allocate big arrays for your data and do the indexing with uint32_t.

So a "pointer" in such a model would be just an index in a global array. Usually addressing with that should be efficient enough with a decent compiler, and it would save you some space. You'd loose other things that you might be interested in, dynamic allocation for instance.

Another way to achieve something similar is to encode a pointer with the difference to its actual location. If you can ensure that that difference always fits into 32 bit, you could gain too.

like image 186
Jens Gustedt Avatar answered Oct 10 '22 07:10

Jens Gustedt