How is long (64-bits) type variables are stored in 32-bits computers?
It's a bit complicated, and I don't know all of the details. That said, 32-bit computers often have the ability to deal with longer data, it just takes more machine instructions, and thus extra processor cycles. On older computers, the compiler will turn out the assembly code needed to do the math correctly on a longer data type, I believe. Moreover, the definition of long varies from instruction set to instruction set, as I recall.
right, on my machine, which is an 64-bit AMD, the C long is 32 bits long (same as the ordinary int), and the C long long is the 64 bit integer type.
On my Commodore 64, the instructions would be executed on the low order byte and if it overflowed, the carry bit was set. Then the next byte was done, and so on. I've always assumed that newer machines just used a larger word, but the same basic procedure.
For the storage part of the question, the bits are simply stored in consecutive words, even though the bits may or may not be contiguous, depending on the operating system. It would be up to the compiler to calculate the proper address of the beginning of the variable.
Join our real-time social learning platform and learn together with your friends!