Jump to content
  • Advertisement
Sign in to follow this  
ianp622

Short or Word?

This topic is 4421 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

Hi, I'm writing a program that writes data to a USB module, which will then transfer that data to a Digital-to-Analog convertor over the SPI interface. (If you don't know what all that means it's not important). I need to send 16 bits of information to the DAC. I would like my program to be as universal as possible on Windows machines (so it always sends only 16 bits), so would I use a short, a SHORT, or a WORD? Or does it not matter?

Share this post


Link to post
Share on other sites
Advertisement
Ok typically a word on a 32-bit system is 4 x 8 bits and on a 64-bit system 8 x 8 bits. I believe that the standard for a short is always 16 bit...

From: http://cplus.about.com

Definition: Shorts are an integral data type used to store integers. They are stored in 16 bits on 32-bit machines, and 32 bits on 64 bit machines. Please see int for more details.

Share this post


Link to post
Share on other sites
SHORT and WORD aren't standard types, however:
The SHORT from windows.h will always be 16 bits.
The WORD from windows.h will always be 32 bits (edit: 16 bits apparently)

The C standard doesn't guarentee the size of short, but I'm not aware of a compiler for the windows platform that doesn't use a 16bit short.

[Edited by - Nitage on July 7, 2006 10:40:08 AM]

Share this post


Link to post
Share on other sites
Assuming C++, you can use boost/cstdint.hpp and use the uint16_t or int16_t types, depending on whether you want a signed or unsigned integer.

However, a SHORT and a WORD are both 16 bits in the Win32 API.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nitage
SHORT and WORD aren't standard types, however:
The SHORT from windows.h will always be 16 bits.
The WORD from windows.h will always be 32 bits.

Correct me if I'm wrong, but as far as I know, on 32-bit Windows:
- SHORT is a typedef for short, which is 16-bits.
- WORD is a typedef for unsigned short, which should also be 16-bits.

Edit: Too late...

Share this post


Link to post
Share on other sites
I did a sizeof(short),a sizeof(WORD), and a sizeof(SHORT), and they all returned 2 bytes. However, this is a 32-bit computer. I'm using windows.h anyway, so from what Nitage said, SHORT seems like what I need. If my program runs on a computer with a 64 bit processor on Windows 64-bit, will the size of SHORT be different?

EDIT: Ha, raz0r, we posted the exact same second. What are the odds?

And yeah, I thought WORD was 16 bits, because that's what I got when I did sizeof().

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
for windows use either

signed __int16
unsigned __int16

Share this post


Link to post
Share on other sites
Ok, thanks for the help everyone. I think I'll go with __int16, since that seems like the safest way to go.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by SiCrane
Assuming C++, you can use boost/cstdint.hpp and use the uint16_t or int16_t types, depending on whether you want a signed or unsigned integer.


Is that really boost? cstdint comes by default with gcc. I thought it was C99?

Share this post


Link to post
Share on other sites
stdint.h is a C99 header. boost/cstdint.hpp is a boost implementation of the same header for compilers that don't come with the stdint.h header.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!