December 15th, 2004, 06:32 PM
Special Types in C++
I'm trying to learn C++ in depth. I should say I've programmed in Java for a few years now (throughout college, 5+ years hehe), so I'm not new to programming and programming concepts.
However, I keep stumbling into problems and riddles in C++. For example, can anyone explain what are those special all-uppercase variable types, like WORD, WSAData, SOCKET, DSWORD, etc, where they come from, how are they defined (macros??).... Intuitively they make sense, but when time comes for me to use them, why should I use type SOCKET instead of int?
If anyone can shed some light on this, I will be forever thankful.
December 16th, 2004, 06:47 AM
well, the types you are explaining are part of the windows API's.
Windows API's are functions that are written by microsoft and which a programmer can use so that it becomes easier to write programs for Windows.
most of the time you need to include the windows.h headerfile to use these functions.
suppose you have the windows API OpenProcess():
as you can see here , the function returns a HANDLE.
a HANDLE here is a handle to the process that is opened, which can be used again in another API.
it is not a real C variable, but more of a structure which is pre-defined in the header file, which allows the programmer to define his own types of variables (sort of).
you can check the msdn site for more info here, or if you google for Windows API you can find several tutorials like this one.
i hope this clears things up. the variables you are using are defined before, some examples:
PROCESSENTRY32 <name of structure>
December 16th, 2004, 05:59 PM
Thanks for the reply WS. I was not aware this is just a part of a Windows API. For the sake of portability, I will try to stay away from this these special variable types whenever I can.
It's kind of interesting how sockaddr_in is defined as SOCKADDR_IN... it doesn't seem to make life any easier, though, to be fair, all uppercase letters tell me (as a Java programmer) that it's a variable defined somewhere else.
In any case, your reply along with White Eskimo's tutorial on preprocessors (http://www.antionline.com/showthread...hreadid=249061) sheds plenty of light on this.
Thank you once again,
Alright Brain, you don\'t like me, and I don\'t like you. But let\'s just do this, and I can get back to killing you with beer.
-- Homer S.