On 4/5/06, Don W. Carr <> wrote:
> And that brings up another point, you should never use sprintf(), use
> snprintf(), where the maximum length is given. Well, there are a
> number of the string functions that should not be used such as:
Arguably, you should never use snprintf() and only use sprintf().
After watching an afternoon-long IRC argument about this, I would like
to add the following points:
- Do not use snprintf() if you want it to be portable, not all
operating systems / libraries have implementations for this.
- You _can_ use sprintf() to act like snprintf :-) you just have to be
very religious in your formatting (which, for me, is far too
annoying.)
- If you are going to be using something non-standard anyway, why not
use asprintf() and avoid losing data?
I realize these do not apply in all situations, but until I heard them
I was a strong advocate of sn* functions as well. I still use them
regularly, but no longer think they are a silver bullet.
-Mark
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|