CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: char vs CHAR

  1. #1
    Join Date
    Dec 2005
    Posts
    445

    char vs CHAR

    Hi guys,

    char is a base language type,
    while CHAR is a windows type declare in windows.h as follows:
    Code:
    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 ??

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: char vs CHAR

    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.
    Last edited by Lindley; March 1st, 2008 at 09:16 PM.

  3. #3
    Join Date
    Jul 2007
    Location
    london
    Posts
    247

    Re: char vs CHAR

    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

  4. #4
    Join Date
    Dec 2005
    Posts
    445

    Talking Re: char vs CHAR

    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.......

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: char vs CHAR

    Quote Originally Posted by Salvadoravi
    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

  6. #6
    Join Date
    Dec 2005
    Posts
    445

    Re: char vs CHAR

    Thank you guys!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured