2

Although there are already a lots of such questions on stack overflow regarding this (almost near to what I want to know). But none of those got the answer that would have solved the case.

My question basically is about following:

Is it possible to implement 64-bit integers using a 32-bit compiler? What is the significance of bit-size of compiler in deciding size of integer? (not considering performance issues)

Somewhat related questions already asked are:

  1. integer size in c depends on what?

  2. Does the size of an int depend on the compiler and/or processor?

  3. What does the C++ standard state the size of int, long type to be?

Each of above question had some very good answers with them but in the end, no one of them gave me an exact answer.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Kush
  • 148
  • 11
  • @MikeSamuel what i believe is that size of integer is only 'implementation-dependent'. It niether depends on compiler nor on machine, being 32-bit or 64-bit or whatever. – Kush Oct 03 '11 at 05:37
  • of course yes, exactly the same way how 64-bit types work on 32-bit platforms or 32-bit types on 16-bit CPUs, or 16-bit type on 8-bit MCUs. [How does a 32 bit processor support 64 bit integers?](https://stackoverflow.com/q/23038451/995714), [Long long int on 32 bit machines](https://stackoverflow.com/q/3072444/995714), [__int64 on a 32-Bit machine?](https://stackoverflow.com/q/2692329/995714), [Do I need to have 64 bit Processor to use 64 bit data type](https://stackoverflow.com/q/5530906/995714), [32 bit operating system supporting 64 bit int](https://stackoverflow.com/q/35102129/995714) – phuclv May 13 '22 at 01:19
  • Does this answer your question? [long long implementation in 32 bit machine](https://stackoverflow.com/questions/330374/long-long-implementation-in-32-bit-machine) – phuclv May 13 '22 at 01:21

4 Answers4

3

int64_t is a 64b integer type and is available if you include stdint.h. uint64_t is the unsigned version and is defined in the same header.

See Are types like uint32, int32, uint64, int64 defined in any stdlib header? for more details.

Is it possible to implement 64-bit integers on a 32-bit machine? (not considering performance issues)

Sure. There's usually no need unless you're on a really restricted instruction set, but it's definitely possible. How to implement big int in C++ explains how to do arbitrary precision integers which is a strictly harder problem to solve.

Community
  • 1
  • 1
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
  • Note the fixed-width types are optional, but almost always available. – rubenvb Oct 01 '11 at 12:54
  • @MikeSamuel I've edited ques and want to know dependency of data types size on compiler. – Kush Oct 03 '11 at 05:41
  • @MikeSamuel I was told that on a 32-bit compiler, maximum integer size can be 32-bit. I totally disagreed with this. – Kush Oct 03 '11 at 05:42
  • 1
    @Kush, I don't know what they mean by "a 32-bit compiler". If they're talking about the difference between `gcc -m32` and `gcc -m64` then that affects the size of `long`, but `long long` is still likely 64 bits and there's no reason why `int64_t` wouldn't be available for `gcc -m32`. – Mike Samuel Oct 03 '11 at 07:38
  • 1
    @Kush 32-bit compiler only means it compiles to an application that executes on a 32-bit machine. A 32-bit architectures can only do arithmetics in 32 bit but this doesn't mean that it cannot do maths 64 bit or more. An `int` on 32-bit machine is generally 32 bit but `long long` (or sometimes `long`) is 64 bit, and there may be many other 64-bit datatypes available as well – phuclv Aug 03 '13 at 02:32
1

Yes. Even on 32 bit machines the .NET Framework provides System.Int64, many C/C++ compilers provide long long/__int64.

Obviously the operations on such types, on 32 bit machines, are somehow emulated (i.e. generally it takes more than an instruction to add two 64 bit integers). For this reason they are available, but are not used unless necessary (and the default int size defaults to 32 bit).

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
0

Yes

In C, their type is usually named long or long long. Or, if your compiler is for C99, you can use the new fixed width types defined when you #include <stdint.h> (or #include <inttypes.h>): int64_t, uint64_t, ...

pmg
  • 106,608
  • 13
  • 126
  • 198
-3

In Java, int is always 32 bit and long is 64 bit, even if on a 8bit machine.

Ingo
  • 36,037
  • 5
  • 53
  • 100