[flac-dev] snprintf and MS Visual Studio

Erik de Castro Lopo mle+la at mega-nerd.com
Thu Mar 14 18:48:57 PDT 2013


Ben Allison wrote:

> Microsoft provides a surprisingly good (but proprietary) API inside
> strsafe.h.

All of which are completely useless from cross platform code. I remember
looking at that stuff at some time and thinking that their API design
was somewhat lacking in clarity or vision (to be gentle).

> StringCchPrintfA can be substituted for snprintf but the return value
> is different.

Thats a big enough difference to make its use highly inconvenient.

>  A small wrapper function around
> StringCchPrintfExA could get you enough information to emulate snprintf
> well.

Sigh, but why not just support the ISO C99 standard snprintf?

> But sprintf_s might be good enough for the limited uses inside flac, as you said.

It is for current usage. I am concerned that all future usage of snprintf
needs be aware of the differences between the ISO C99 version and the
Microsoft version.

I suspect the best way to avoid this is wrap both inside a flac specific
API and only use the flac specific version.
 
Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/


More information about the flac-dev mailing list