4 ms·
I am actually happy that gcc doesn't find it important to support a library that prevents its users from using functions that are clearly defined in the specifi
by yalue 13y ago
I am actually happy that gcc doesn't find it important to support a library that prevents its users from using functions that are clearly defined in the specification of the language it supports.
- panzi 13y agoI don't understand why functions like gets and sprintf weren't removed from the standard and headers a long time ago. It can't be for legacy reasons, because removing them from the headers has no effect on binaries and when you compile source it should easy to replace gets with fgets and sprintf with snprintfe etc. These functions have no right to exist.
- finnw 13y agogets has no right to exist. But sprintf does. It's a workaround for some old embedded C compilers that lack the safe string copy functions (strcpy_s, strlcpy.) char dst[5]; sprintf(dst, "%.*s", (int)sizeof(dst)-1, "Hello!"); Copies a null-terminated string to dst, truncating if necessary to avoid overflow. Just don't forget the "." or the "-1".
- tedunangst 13y agoThat code is just as easily converted to use snprintf, and then you don't need to worry about the . Or -1.
- epsylon 13y agosnprintf is C99 IIRC. Which means legacy C89 compilers (or worse!) don't have it.
- panzi 13y agoWhich brings it back again to my initial comment: "I don't understand why functions like gets and sprintf weren't removed from the standard and headers a long time ago." And by a long time I mean before 1989 (certainly before 1999).
- atesti 13y agoWhy should I not be allowed to allocate a buffer that has like 10 or 20 extra characters of space and use a format string with %d in it? Why does sprintf have to be banned? But banning gets is obvious because it is by definition facing external input
- jheriko 13y agoit should always be optional, just like the ms implementation, also this is part of a standard too...