🔒 Locked
Hungarian notation
Advertisement
Original Post
Hi everyone,
I''d like to know if there''s someone out there who could tell me something more about Hungarian notation. I hope it is what I mean
ie.
int iNumber;
LPSTR szString;
etc.
is there some description somewhere? Do you use it and if, how often. If not, what style do you prefer.
I don''t know all of Hungarian notation, but I picked up on some of it reading over various Win32 C sources.
The most important part of a naming convention is to indicate the scope of the variable. There''s some disagreement on whether or not HN (aka waRTs) improve the "readablity" of the code.
This is the scheme that I use:
Magmai Kai Holmlor
- Not For Rent
The most important part of a naming convention is to indicate the scope of the variable. There''s some disagreement on whether or not HN (aka waRTs) improve the "readablity" of the code.
This is the scheme that I use:
Prefixes:
g_ global
m_ member property
ms_ static member
<no prefix> local
Postfixes:
_ function or method parameter
_<unit> to indicate what units a measurement is in
|
Magmai Kai Holmlor
- Not For Rent
My typing style changes all the time, but currently I use scope prefixes and that''s it. Magmai lists most of them, here''s one more:
s_ - static (usually can be either local or global)
True Hungarian Notation involves one or two letters identifying the type of the variable. Most people really hate this, but it really makes code much easier to understand for people who didn''t write it. Tutorials should use this notation, in my opinion. Microsoft uses it because its code is worked on by many people, and this makes it easier for that to happen, so they can understand each other''s code.
Here are some type prefixes:
i - Integer. Signed, either 16-bit or 32-bit
l - long. That''s a lowercase L
c - char
s - array of char. In other words, a string NOT terminated by zero
Example: char sRGB [3];
sz - string terminated by a zero
Example: char* szText = "Hi, world!";
a - array, followed by type. Sometimes ''r''
Example: int aiArrayOfInt [5];
f - float
d - double
u - unsigned, followed by type
Example: unsigned long ulWidth;
b - byte, same as unsigned char
w - word, same as unsigned short
dw - doubleword, same as unsigned long
p - pointer. Usually not followed by anything
Example: float* pAges;
usually not: float* pfAges;
Scope stuff comes before type stuff.
Example: g_szName
not: szg_Name;
~CGameProgrammer( );
s_ - static (usually can be either local or global)
True Hungarian Notation involves one or two letters identifying the type of the variable. Most people really hate this, but it really makes code much easier to understand for people who didn''t write it. Tutorials should use this notation, in my opinion. Microsoft uses it because its code is worked on by many people, and this makes it easier for that to happen, so they can understand each other''s code.
Here are some type prefixes:
i - Integer. Signed, either 16-bit or 32-bit
l - long. That''s a lowercase L
c - char
s - array of char. In other words, a string NOT terminated by zero
Example: char sRGB [3];
sz - string terminated by a zero
Example: char* szText = "Hi, world!";
a - array, followed by type. Sometimes ''r''
Example: int aiArrayOfInt [5];
f - float
d - double
u - unsigned, followed by type
Example: unsigned long ulWidth;
b - byte, same as unsigned char
w - word, same as unsigned short
dw - doubleword, same as unsigned long
p - pointer. Usually not followed by anything
Example: float* pAges;
usually not: float* pfAges;
Scope stuff comes before type stuff.
Example: g_szName
not: szg_Name;
~CGameProgrammer( );
Might I add prefix for STL containers/adapters?
I hardly ever use plain arrays or C-style strins anymore in my own code. It''s only in those regrettable places where I have to interact with existing interfaces... speaking of which, does anyone know how to pass the contents of an STL string to Speak() in the MS Speech API?
vec - vector<>
str - string<>
lst - list<>
map - map<>
...
I hardly ever use plain arrays or C-style strins anymore in my own code. It''s only in those regrettable places where I have to interact with existing interfaces... speaking of which, does anyone know how to pass the contents of an STL string to Speak() in the MS Speech API?
Doesn''t string::c_str() work? Or does it want a non-const string? Maybe const_cast would work. I dunno...
---------------
I finally got it all together...
...and then forgot where I put it.
---------------
I finally got it all together...
...and then forgot where I put it.
quote:
Original post by AdmiralBinary
Doesn''t string::c_str() work? Or does it want a non-const string? Maybe const_cast would work. I dunno...
For some bizarre reason, Speak() takes a const WCHAR * for the text. When specifying the text hardcoded, one must use the L macro:
pVoice->Speak(L"Hello", ...);
I haven''t found any conversions from any of the C-style strings to WCHAR * (which is actually an unsigned int *).
LOL, I s''pose this wouldn''t be any good to you?
---------------
I finally got it all together...
...and then forgot where I put it.
|
---------------
I finally got it all together...
...and then forgot where I put it.
Ooooooh, my first double-post, sorry...
---------------
I finally got it all together...
...and then forgot where I put it.
---------------
I finally got it all together...
...and then forgot where I put it.
WCHAR is a "Wide Character". This is for UNICODE characters, these are used so that foreign languages with more than 256 characters/glyphs/letters which are possible with ANSI can be represented - a common example is one form of Japanese which has over 3000 characters. Using 16 bits per character (WCHARs are 2bytes/16bits each) allows 65536 possible characters. For more information on UNICODE look at: http://www.unicode.org/
Windows NT/2000/XP use UNICODE internally so many Windows APIs which were originally written for NT only take UNICODE strings.
There is a third form of character in Windows called Multi-Byte-Character-Set (MBCS), in this is like a hybrid between ANSI and UINCODE where western characters (A-Z etc) are represented with just a single byte. For characters which won''t fit into the 0-255 range, a special code is used to mark the introduction of an extended code so that individual characters could take different amounts of space between 1 and 3 bytes each.
Unicode is the easiest and standard way to represent strings in languages with lots of characters.
Some Windows calls to look up for conversion of strings:
MultiByteToWideChar()
IsTextUnicode()
--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
Windows NT/2000/XP use UNICODE internally so many Windows APIs which were originally written for NT only take UNICODE strings.
There is a third form of character in Windows called Multi-Byte-Character-Set (MBCS), in this is like a hybrid between ANSI and UINCODE where western characters (A-Z etc) are represented with just a single byte. For characters which won''t fit into the 0-255 range, a special code is used to mark the introduction of an extended code so that individual characters could take different amounts of space between 1 and 3 bytes each.
Unicode is the easiest and standard way to represent strings in languages with lots of characters.
Some Windows calls to look up for conversion of strings:
MultiByteToWideChar()
IsTextUnicode()
--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement