[Development] #pragma or xxx_s functions

Nicolás Alvarez nicolas.alvarez at gmail.com
Thu Dec 19 02:05:28 CET 2013

2013/12/18 Kurt Pattyn <pattyn.kurt at gmail.com>:
> For a lot of the standard C functions, Microsoft has implemented "safe" versions.
> Functions like sprintf, scanf, strcpy, aso have "safe" counterparts with an _s suffix: sprintf_s, scanf_s, aso
> When the "non-safe" functions are used, the Microsoft compiler generates a warning that these functions should be replaced by their "safe" counterparts.
> There are 3 ways to get rid of these warnings:
> 1. replacing those functions,
> 2. using a #pragma
> 3. using a compiler flag
> What is the recommended way to get rid of these warnings in the Qt sources?
> I solved these warnings by replacing the calls with the safe versions, but the patch was rejected because it was recommended to use #pragmas.
> Before proceeding and going through the sources again, I would like to know the recommended practice within Qt.

The so-called safe functions with the _s are Microsoft extensions and
don't exist in other platforms. Changing to the "recommended" "safe"
functions makes the code only compile and work on Windows.

I don't know how Qt handles this, but in other projects the solution
I've seen is to just define _CRT_SECURE_NO_WARNINGS globally.


More information about the Development mailing list