5 ms·
C++26: Deprecating or removing library features
- johnisgood 2y agostrtok was removed from C, too? Damn. I guess I am sticking to C99 regardless.
- lifthrasiir 2y agoDon't use strtok, it was already painful to use in C99. It is not even that hard to emulate using strstr if you do need one.
- nesarkvechnep 2y agoThe OC is the type of person to tell you the problems of C are all skill issues.
- Lanolderen 2y agoAlways have been (⌐■_■)
- ape4 2y agoUse strtok_r()
- lifthrasiir 2y agoThat also works, but strtok is of so limited use that it's probably better to roll your own anyway. For example you can't handle arbitrary whitespace with strtok.
- deleted 2y ago[deleted]
- johnisgood 2y agoman -a strtok with all manual pages installed[1] (POSIX, Linux, BSD), you get a pretty good idea as to how to use it properly, or reading the SEI C Coding Standard helps. OpenBSD deprecated it in favor of strsep. It is not painful to use if you know (read all the manual pages at the very least). Been happily using it for a long time (unless other functions are not more ideal for the specific use-case). There are some things to pay attention to, but the manual pages pretty much tell you everything you need to know. [1] https://archlinux.org/packages/core/any/man-pages/ https://archlinux.org/packages/core/any/man-pages/ on Arch Linux, perhaps it is "man-pages" for other distros, too. As per Arch wiki: "man-pages provides both the Linux and the POSIX.1 man pages". You may also do: curl -sL 'https://man.archlinux.org/man/strtok.raw' | man -l - or curl -sL 'https://man.archlinux.org/man/getaddrinfo_a.raw' | man -l - for "strtok", although not sure it provides ALL manual pages.
- GuB-42 2y agoIf your use case is covered by strtok(), why not? Like all functions, you have to use it properly, and the use case for strtok() is narrow, but sometimes, it is just what you need. I rarely use it myself, but emulating it is silly. Also strstr() is probably not the most appropriate, maybe you mean strpbrk()? As far as I know, the only function from the libc that you should never use is gets(). It is even written in the manual: "Never use this function". As expected, it is removed from recent standards.
- johnisgood 2y agoExactly. There is also "strsep"[1]. [1] https://man.openbsd.org/strsep.3 https://man.openbsd.org/strsep.3
- kstrauser 2y agoDoesn't that modify the input in exactly the same way strtok does?
- duskwuff 2y agoThe worst problem with strtok() isn't that it modifies its input; it's that it's stateful. It retains a pointer to the input string internally, and returns subsequent words from it when called with an input of NULL. strsep() fixes this by using a char * argument instead.
- duskwuff 2y ago... and HN's formatting mangled that, yay. I meant a char ** argument.
- LegionMammal978 2y agoIt wasn't removed, it was just taken off the list of freestanding functions.
- zabzonk 2y agoI'm amazed it has taken so long to get rid of strtok(). This is one of the worst designed and most misused functions I have ever seen - just about every use of it I have ever come across has been wrong. Write your own mini-parser rather than use it.
- johnisgood 2y agoI'm amazed people who are skilled in C find it difficult to use, considering everything you have to know about it is available in man-pages (and pretty much everywhere online). If it is misused, that is a skill issue (yeah, sorry). I could misuse virtually anything in other languages, too... So, all in all, I don't understand what you are trying to say. There are cases where I would rather use strtok than to roll my own. Sometimes all you need is already available, e.g. strtok, or strsep, or strstr, or what have you. Consider that I misuse this and that in your favourite language. Is it a reflection of the programming language, or my limited "skills"? https://wiki.sei.cmu.edu/confluence/display/c/STR06-C.+Do+not+assume+that+strtok%28%29+leaves+the+parse+string+unchanged https://wiki.sei.cmu.edu/confluence/display/c/STR06-C.+Do+no... is worth a read, too.
- IshKebab 2y ago> If it is misused, that is a skill issue (yeah, sorry). No it isn't. It's very easy to misuse so even skilled people misuse it. > Consider that I misuse this and that in your favourite language. Is it a reflection of the programming language, or my limited "skills"? Depends on what this and that are. If they are things that are easy to misuse and many people do, then it's a reflection of the programming language. If they're well-designed and it's only you getting it wrong, then it's your limited skills.
- johnisgood 2y agoIf what you need is strtok, use it as documented. If you do not use it as documented, that is a skill issue. Do you even need strtok? If you do, RTFM. > If they are things that are easy to misuse and many people do, then it's a reflection of the programming language. If they're well-designed and it's only you getting it wrong, then it's your limited skills. Whatever "well-designed" means. At any rate, wonder where you got the "many people" from, who actually have read the manual. For some of my use-cases, strtok is designed well enough. If I need something else, then I will use something else, and so should you. No need to re-implement strtok (or any other functions) readily available. Plus, do you really think people who cannot use strtok properly can roll their own?
- kstrauser 2y ago> It was an easy-to-use API so it was deprecated by C++20, That tracks with my experiences with C++.
- zabzonk 2y ago> easy-to-use API A lot of C (not so much C++) programmers thought it was easy to use correctly. Mostly, they were wrong.
- indigoabstract 2y agoI think he meant an easy to misuse API.
- optimalsolver 2y agoAccidentally correct is the best kind of correct.
- alecco 2y ago> While the old API expected that the shared object is not used directly, the API made it possible which led to undefined behaviour, typically producing a data race. - C++ is insecure, don't use it [C++ fixes a hole] - C++ always deprecates the easy APIs [Stanley face]
- kstrauser 2y agoI get what they were trying to say, but the exact phrasing amused me. It read like: "This feature was too easy and convenient, so we yanked it."
- Jyaif 2y ago> It was an easy-to-use API so it was deprecated by C++20, along with the introduction of its type-safe replacement std::atomic<shared_ptr<T>>. Is this humor? nit: the contrast between the font and the background is too low
- flqn 2y agoI think the author misspoke and meant to say "easy-to-misuse" instead, which it definitely was.
- superkuh 2y agoLuckily most C++ developers don't immediately jump on and begin using backwards incompatible features. The C++ community is still only recently generally requiring C++11. And that's great. Introduce new features but don't immediately use them in practice. Some other languages and their communities could really learn from this.
- jcelerier 2y ago> The C++ community is still only recently generally requiring C++11. this doesn't match what I see. The Jetbrains 2023 survey reported that 80% of C++ in use was >= C++17. Qt, one of the most common C++ UI framework, has been requiring C++17 for five years and support C++20 types in its API.
- superkuh 2y agoAh, Jetbrains must be touching a different part of the elephant. My related experience is with compiling C++ programs meant for human people to run on their own home computers. I imagine internal company dev projects like Jetbrains would cover don't care nearly so much about compatibility. Also I note that 25%+ of the Jetbrains 2023 survey use C++11 or older. And 50% of Jetbrains survey devs say "No, I don't plan to move to another C++ standard" from C++11. So it's likely that 25% will stay high.
- devnullbrain 2y agoC++14 minimum is the standard
- mrlonglong 2y agoI agree. We recently moved to C++14 because we wanted shared_ptr<> and make_shared<>. Made our lives immensely easier.
- IshKebab 2y agoNah it's not just Jetbrains. C++17 is the bare minimum at this point. It's even the default in GCC.