Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Densun

int vs. long

This topic is 6056 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
''int'' is a mere 3 letters long, whereas ''long'' is an unbearable 4 letters. Using int can save you lots of typing time in the long run.

Share this post


Link to post
Share on other sites
quote:
Original post by krez
just in case: you can fit twice as many 32-bit integers as 64-bit ones into the same memory...

Are you saying that a long is 64-bits? I always thought it was 32.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
a long takes up 8 bytes of memory as aposed to an integer which takes 4 bytes.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Um... actually.. in most c++ compilers an INT is 32-bits, and a LONG is ALWAYS 32-bits... an int can be of different sizes, so for cross compiler compatibility, I always use short for 16-bit numbers, and long for 32-bit. I try to avoid int''s whenever possible. ANSI C/C++ standard states that a short shall be 16-bit data type, and a long shall be a 32-bit data type, an int is dependent on the target. 16-bit compilers (Borlan Turbo C/C++ series for Dos for example) defined int''s as 16-bits, while MSVC (32-bit compiler) defines int''s as 32-bits... once 64-bit compilers start coming out, int''s will be defined as 64-bit, etc, etc. It''s safer to stick with short/long''s that way you know exactly what you''re getting/using. Even though it''s an extra letter for every time you type long instead of int .

Billy - BillyB@mrsnj.com

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Oh, and by the way... long takes up 4 bytes, aka 32-bits.

Billy - BillyB@mrsnj.com

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I guess we''ll forgive you .

Billy

Share this post


Link to post
Share on other sites
This comes up over & over & over & over...

The only thing the standard says is that:

sizeof(char) == 1
sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)

There are no guarantees that an int is going to be 32 bits (or whatever). The only guarantee you have is that an int is at least as big as a short and no bigger than a long.

You''re not even guaranteed that sizeof(char)==1 (8-bit) *byte*. You''re only guaranteed that it is 1 *something*.

Practically speaking of course if sizeof(char) was anything other than one 8-bit byte it would break virtually every non-trivial C/C++ app written in the last 15 years or so. The same *cannot* be said of short, int, and long. The sizes of these can, and have, changed between compilers, OS''s, etc.

In MSVC on Win32 short=16 bits, int=long=32 bits, but that is only true for that specific platform.

-Mike

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!