Author Topic: Different sizeof(long) values in W7 and Linux Mint  (Read 2494 times)

Offline Marnix

  • Multiple posting newcomer
  • *
  • Posts: 19
Different sizeof(long) values in W7 and Linux Mint
« on: January 10, 2016, 09:50:35 pm »
IDE: Code::Blocks 13.12
Compiler: GNU GCC
Language: C
Platforms: W7 and Linux Mint

Short version: On W7 I get sizeof(long) 4 bytes and on Linux Mint it is 8 bytes. I would like to have the same sizeof(long) on both platforms but cannot figure out how.

Longer version: I wrote a compiler and interpreter for a self defined language. The compiler - obviously - generates a code file that is read by the interpreter. I want to be platform independent with the compiled file. So, a file created with the Windows compiler must be readable by the Linux interpreter and vice versa. I can't get the compatibility to work. I noticed that in Windows, the sizeof(long)=4 and in Linux, sizeof(long)=8. As the compiler will write long integers to the output file I think the difference in size is (part of) the problems I have.
Is there a way I can change the sizeof(long) value?

I did search the forums for 'sizeof' and 'sizeof(long)' but with no luck. If I missed a post explaining this issue, I apologize and would appreciate a pointer.

Thanks for reading.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Different sizeof(long) values in W7 and Linux Mint
« Reply #1 on: January 10, 2016, 10:18:27 pm »
Have fun: https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models
If you want to have a specific size used a type with the size suffix in it like uint64_t.

BTW: This is not a topic that is allowed here, because it is a general programming one instead of C::B related. Re-read the rules please.

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]