Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference between data types?

Status
Not open for further replies.

dtrotzjr

Technical User
Feb 5, 2001
11
US
I am new to MS Visual C++ and I am currently reading "Programming Microsoft Visual C++" 5e to get up to speed with the Internals of MFC. It is a good book but one thing it doesn't attempt to do (and they explain why in the introduction) is explain all of the Classes, Stucts, Keywords etc. in detail. So as I come across these new parts of MFC that seem unclear I look them up in the MSDN Library and find most of what I need to know in more detail. But I am confused why MFC uses the data types they use when many of them seem to be the same. For instance:

UINT is an unsigned integer
DWORD is a 32 bit unsigned integer
WORD is a 16 bit unsigned integer

I assume that the last one is defined somewhere as follows:
typedef unsigned int UINT;

But what are the last two? Why does MFC define them, if they are the same as built in C++ data types, or are they? Can someone clarify this for me. Thanks in advance.
David
 
Well, knowing Microsoft, they do this because they don't want their code to be easily portable. If you used an:
unsigned int t;
instead of
UINT t;

you could port the code without any trouble, however, if you use the latter case, you can't port the code and get it to compile nicely. This is sort of a paranoid answer, but it's probably at least partially correct. This in effect guarantees that all of the m products are proprietary.

As always, I hope that helped!

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
I wouldn't doubt that you are right, but I am sure they have an engineered reason for creating these data types. That is what I am after. Thanks though for your help.
 
Waayyyyy back in the days when I first started programming, I started with machine language stuff. In machine language there are no data types, but there are terms used to refer to the amount of memory used for storage. The terms included:

BIT - Binary digIT.
NYBBLE (aka nibble) - four bits.
BYTE - eight bits.
WORD - two bytes.
DOUBLE WORD (or dword) - four bytes.

I think that the typedefs you've identified were provided by the folks at M$ simply in support of old machine language programmers - a way to give them something familiar to work with.

Code:
typedef unsigned char
Code:
BYTE;
Code:
 // 8 bits
Code:
typedef unsigned short
Code:
WORD;
Code:
// 2 bytes
Code:
typedef unsigned long
Code:
DWORD;
Code:
// 4 bytes

Bits and nybbles are modifyable but not addressable and therefore there aren't any typedefs for them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top