Re: Output ANSI text from generic code

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Mitch Gallant" <jensigner@xxxxxxxxxxxxxxxx> ha scritto nel messaggio news:eAEk$rPkJHA.4880@xxxxxxxxxxxxxxxxxxxxxxx

My app is a C windows application which I'd prefer to keep as C. However I did try T2A and it worked perfectly after changing the code to .cpp from .c and recompiling with the required atl headers.

I suggested CT2A, which I prefer instead of T2A.
CT2A has been being available since VS2003 (a.k.a. VC7.1), instead T2A was something from VC6 (ATL3).
CT2A has some advantages over T2A, as you can read from a comparison table shown here:

http://msdn.microsoft.com/en-us/library/87zae4a3(VS.80).aspx

"Old ATL 3.0 Conversion Macros" vs. "New ATL 7.0 Conversion Classes"

Regarding changing a windows C application to cpp and recompiling, if I don't introduce any classes or CPP code in the original C code (except say for the T2A or CT2A macros) and rcompile as .cpp, does the resultant compiled/linked code change significantly in a way that migh changed a "real-time" (i.e. waveform sampling) application?

I believe that the performance of your app won't change as a result of this simple C++ recompilation :)
Your new .CPP app will be just fine.

Any other issues with changing from C to CPP from original C code?

I think that you will just have a cleaner code, and better type checking.
In fact, the C++ compiler tends to be more careful about strict type checking than a pure C compiler, so I think that if you "write C code" in ..cpp files and so use the C++ compiler to build the final binary, you may have an increased quality in your source code.

I think that C++ is a very complex language, but you don't need to be a "language lawyer" to be productive with it (unless you want to develop some core library like STL!).

The first step is to just take your C code, rename the file to .cpp, and do a rebuild. If the C++ compiler complains about errors or warnings, they may be due to type mismatch and stricter C++ type checking. So, trying to fix your C code to compile as C++ code without errors and warnings will increase the quality of your code.

Next step would be to refactor your code, moving data structures and global functions into proper classes and methods. Data structure fields become class data members, and functions related to some data structures become methods of that class (sort of).
This is another step in the direction of making your code of better quality.

Then you can use other tools that C++ offers, like inheritance, templates, exceptions for error management, etc.

Regarding my original question, the motivation was that I want the text-generic application to always write out ANSI text files .. not UNICODE.

I consider that safe only if you use pure American text (i.e. a-Z, 0-9, etc.).
If you start using Italian accented characters like è é ò etc. or something from Japanese or Chinese, or Greek letters, etc. I think that ANSI/MBCS becomes a kind of "pseudo-random" format to store text (you will become dependent upon code pages, etc.).
Unicode (be it UTF-8 or UTF-16) is a cleaner solution to store internatinal text, IMHO.

HTH,
Giovanni

.



Relevant Pages

  • Re: Cpp Considered Harmful
    ... programming language, the compiler, the IDE, the libraries, etc. ... WRT exceptions, the fact of the matter is that placing certain ... >> regarding the CPP. ...
    (comp.lang.cpp)
  • Re: Output ANSI text from generic code
    ... I did try T2A and it worked perfectly after changing the code to .cpp ... I suggested CT2A, which I prefer instead of T2A. ... the C++ compiler tends to be more careful about strict type ... and functions related to some data structures ...
    (microsoft.public.vc.language)
  • Re: can preprocessor automatically make N array elements?
    ... # Can m4 statements be inserted into C code, like cpp statements? ... A C compiler traditionally includes a cpp step, ... although the loader is not traditionally part of the compiler. ... I don't if/where the ATT documentation is. ...
    (comp.lang.c)
  • Re: Compiling -- gcc -- Lex & Yacc
    ... cpp, was CREATED using lex and yacc (or more correctly, their Gnu ... It does eventually call the assembler and the ... the gnu site offers me the same 'info gcc' document that I ... of your compiler knowledge I am trying to find. ...
    (Fedora)
  • Thanks for the info... ^.^
    ... > definition in one of the source (.cpp) files. ... > This definition is where you can place the initialisation of the members, ... which basically meens that compiler is bad to ... my only problem was i declaired a "static gizmo myStaticGizmo" ...
    (alt.comp.lang.learn.c-cpp)