What is the best way to find widespread headaches like L "% s"?

Here's an example of one of the headaches I'm talking about:

We have a multi-platform project that uses mostly Unicode strings to render text to the screen. On windows in VC ++ the line:

swprintf(swWideDest, LEN, L"%s is a wide string", swSomeWideString);

      

compiles and prints a wide string to another wide string. However, this should be valid:

swprintf(swWideDest, LEN, L"%ls is a wide string", swSomeWideString);

      

Without replacing "% s" with "% ls" this will not work on other platforms. Because testing in our environment on Windows is easier, faster, and much easier to debug. These errors can be easily spotted.

I know that the best solution is, first of all, to write the correct code, but simple mistakes are made under pressure, and in this particular case, the error can easily go unnoticed for a long time.

I suspect there are many variations on this error that we haven't received yet.

Does anyone have a good and neat way to find errors like this?

: D

+2


source to share


2 answers


Since none of the functions in the family *printf

are typical, you either



  • finding probable errors using regular expressions and fixing them manually
  • use a different approach that is typical, perhaps based on string streams or boost.format
+2


source


You might want to look at FastFormat in case Boost.Format is too slow for your needs.

Compared to strings and Boost.Format:



  • IOStreams: FastFormat.Format is faster than IOStreams, between ~ 100-900%, in all cases
  • Boost.Format: FastFormat.Format is faster than Boost.Format, between ~ 400-1650% in all cases
+4


source







All Articles