Silly sprintf question

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Mr. Moxie
Posts: 48
Joined: Thu Dec 06, 2007 7:55 pm
Contact:

Silly sprintf question

Post by Mr. Moxie »

I'd like to know if I should be using _sprintf or sprintf in my code? I want my current game to cross platform, but I don't know if Mac or Linux uses the secure versions of sprintf or stricmp. Haven't bought my Mac for development yet.
George A Lancaster
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I don't think _sprintf exists on other platforms, this looks like a MS specific extension (and man - do I hate all the warnings they added for the old versions as lots of libs out there don't use pragmas to disable them and so compiling with VS can produce hundreds of warnings these days!).

The safest way to work (and which is platform independent) is anyway to use c++ streams instead of sprintf, but I admit that I also still often use the printf stuff.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Mr. Moxie
Posts: 48
Joined: Thu Dec 06, 2007 7:55 pm
Contact:

Post by Mr. Moxie »

Thanx,

That's what I thought, I'm just going to disable the various warnings with: _CRT_SECURE_NO_DEPRECATE since I have too many sprintf(s) in my existing code, and debug libs.
George A Lancaster
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You should never use sprintf, but the snprintf is pretty safe. Furthermore, Irrlicht replaces the snprintf by _snprint or s_sprintf depending on the MSVC version you use.
Post Reply