Click to See Complete Forum and Search --> : char vs CHAR
Salvadoravi
March 1st, 2008, 06:45 PM
Hi guys,
char is a base language type,
while CHAR is a windows type declare in windows.h as follows:
typedef char CHAR;
I can't understand why whould I need it??
if CHAR equel to char why use it, and why windows.h bother creating a new type for it ??
Lindley
March 1st, 2008, 08:13 PM
windows.h does things like that all the time. Smile and nod.
I'm sure someone thought at one time that it might be a good idea, and ever since then that's been Just The Way It Is.
Also, using such typedefs would theoretically allow code to survive changes to the underlying language (such as how large a char is), simply be altering the typedef. However, since Microsoft wrote the most common Windows compiler, and has no interest in porting Windows to other systems, this seems like needless effort.
g3RC4n
March 1st, 2008, 08:36 PM
lol, i've never really understood it either seeing as if you use CHAR the ide doesn't highlight it so theres only a disadvantage, but i guess because it's consistent with all the caps with all the other typedefs
Salvadoravi
March 2nd, 2008, 05:51 PM
lol, I noded and I have a huge smile on my face (nice message Lindley), but I can't let it go, I must find a reason why to use CHAR over char, I tried to find an answer on google for the last 2 hours with Zero results.
I must find one, It just doesn't make any sense, but there must be one otherwise it woulden't go into windows.h.....
Please find me a reason.......
Paul McKenzie
March 2nd, 2008, 06:54 PM
I must find a reason why to use CHAR over char, I tried to find an answer on google for the last 2 hours with Zero results.Those macros go back more than 18 years. They were used in the original Windows 1.0 API, and were brought forward to make sure that existing code using them did not break. That is why they're still around today.
It was just the Microsoft's engineers idea to make sure that a Windows API programmer never have to specify a 'C' type explicitly when using API functions, that's all. Look at LONG, BOOL, UCHAR, etc.
Regards,
Paul McKenzie
Salvadoravi
March 3rd, 2008, 04:50 AM
Thank you guys!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.