Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

g++ - gcc, width of long int on different architectures

On 64-bit architectures, long int, according to gcc is at least an int64_t. On 32-bit, long int is at least int32_t. With Microsoft compilers, long is always an int32_t, regardless of 32/64-bit. Is there any way to:

  1. Force gcc to treat long as a int64_t, on 32bit? (for ease of testing)
  2. Force gcc to treat long as a int32_t on 64bit? (for compliance with MS's compiler).
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Don't do this - use standard types such as int32_t, uint32_t, int64_t, uint64_t, etc from <stdint.h> rather than trying to make assumptions about naked types such as long int or trying to bend the compiler to your will.

Note: The 64-bit model for any given platform (e.g. LP64 for most *nix platforms, Mac OS X, etc) is a given, so even if you could convince the compiler to use a different 64-bit model you would probably break any calls to system code, libraries, etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...