Thread: convert from int to cstring

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I see what you mean. But I also have to draw a line somewhere. I won't use unsafe functions, because they can compromise security and stability.
    Macros, however, are compile-time, and if a macro works, good for me, than I can use it. There's no "unsafe" I see in using macros, even if they're served.
    But as you point out, I could just make an own macro, __T(?) or ___T(?) and just map it to _T, or if it does not exist, someone else will have to remap that macro into something else that works. Or just redefine it so it works.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Function or macro names that start with an underscore are reserved for compilers.

    Edit: I wouldn't redefine a compiler macro tbh.... especially for something like this.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    But T is too generic, and TEXT may be too generic and I don't want to type CONVER_THIS_TO_ASCII_OR_UTF.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    But TEXT is what the Win32 API uses. Can't be too generic.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    THIS IS A TEXT!
    ...Or so I'd like say -> but if I type that in my app, what will happen, I wonder? That's why I use _T. That and it's shorter too.
    That's why it's maybe too generic.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    but if I type that in my app, what will happen, I wonder?
    You mean in a text field during runtime or something like that?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, something like that.
    It's just that it will be replaced by the TEXT macro which is something you'd want to avoid.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Unless you need to support Windows 95, their is no need to use _T() or TEXT() in a Windows application. If you're not planning on running on 95, then only use "wide" APIs. For MFC, that means you have to define UNICODE and _UNICODE since it uses TCHAR's (for 95 support). Then you can put a nice big ell in front all your static strings, instead of having to macro-wrap them.

    gg

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Here's a good question: is there any platform that is ASCII only or ASCII specific?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #25
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by Elysia View Post
    Yes, something like that.
    It's just that it will be replaced by the TEXT macro which is something you'd want to avoid.
    You really need to review the compilation model of C++. What you fear is utterly impossible.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #26
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Yeah, I can't help thinking that the issue isn't being clarified properly. Typing in "TEXT" as input into a program doesn't invoke a macro of the same name, and I can't imagine they actually think that.

  12. #27
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If everyone were experts, we wouldn't need experts. You don't know everything and you will never do. You learn something every day as they say.
    I didn't know, of course.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #28
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Macros are handled the by (C) preprocessor at compile time. I had thought you even previously had said that they were handled at compile time.

    To be slightly pedantic, they are handled before compile time..... An example:

    Code:
    #define SIZE 10
    
    ....
    
    int array[SIZE];
    
    ....
    The preprocessor actually runs through the code and replaces all instances of SIZE with 10, so that before the code is actually even really compiled, SIZE is replaced with 10.

    So the code is really looked at by the compiler is this:

    Code:
    ....
    
    int array[10];
    
    ....
    That's all #define does for you, whether implemented as _T() or whatever else.

    The special stuff is that the _T() macro checks if Unicode is define or not and if so then it makes the string a wide one (with L). Otherwise, it doesn't do anything. The source code is changed in memory before it actually gets compiled, though. There's no need to worry about it after that.

    On a slightly different topic, I read an article, though, that said that _T() and TEXT() are actually different. Some are implemented to handle something to do with the C library and another is to handle something different with Windows API functions or something. I'd have to look it up again to see exactly what the difference is.

  14. #29
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Strictly speaking, the _T macro doesn't check. There's actually two _T macros, but only one is ever defined.

    The definitions of the two _Ts, of the two _TEXTs and the two TEXT macros are:
    In <tchar.h> (MS CRT extension)
    Code:
    #if defined(_UNICODE)
    #define _T(x) L ## x
    #define _TEXT(x) L ## x
    #else
    #define _T(x) x
    #define _TEXT(x) x
    #endif
    In <windows.h> (Win32 API)
    Code:
    #if defined(UNICODE)
    #define TEXT(x) L ## x
    #else
    #define TEXT(x) x
    #endif
    As you can see, the CRT and the Win32 versions are identical, except for the macro they test against.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  15. #30
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by CornedBee View Post
    Strictly speaking, the _T macro doesn't check.
    Sorry, you are correct.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  2. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  3. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 07:45 AM
  4. Replies: 4
    Last Post: 11-23-2003, 07:15 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM