4 ms·
This article is just apologism for the status quo. Nothing new here. > Memory allocation, array and string handling are often tricky, but with the right librar
by pshc 4y ago
This article is just apologism for the status quo. Nothing new here.
> Memory allocation, array and string handling are often tricky, but with the right libraries and a sound memory strategy, it can be minimized.
Such a handwavy deflection. Parsing strings in C is a joke and also a minefield bursting with vulnerabilities. And if you use null terminated strings (which you are, let’s face it) it’s slow.
- gregoryc_ 4y agoDepends on the functions used. memcpy is better than strcpy
- pshc 4y agoI’m sure you meant something more along the lines of “strncpy is better than strcpy”.
- gregoryc_ 4y agomemcpy is better than strncpy and strcpy ;)
- naniwaduni 4y agoNah, strncpy is pretty bad and doesn't do something anyone really expects to want. (strncpy doesn't 0-terminate when it hit max length, nor stop when it sees its first 0 in the source buffer; it acts almost entirely like memcpy except that it writes zeroes to the full length of the destination upon seeing a zero in the source. This is allegedly useful for populating fixed-sized buffers in historical Unix, and can plausibly be useful for writing out tar headers, but in practice very little code in the wild does anything observably different if you #define strncpy memcpy.)
- krater23 4y agoOk, but there exists a sulotion for this. Using C++ with STL. Why we exactly need a new language?
- ChrisRR 4y agoThere is A solution. Is it the best solution? Are there other solutions which may offer better performance or safety. I don't we should stop trying to improve just because an existing solution exists, especially in the space of systems programming which has barely moved in decades
- pjmlp 4y agoThe only way to real achieve progress in systems programming is through generation change, one person at a time, the problem isn't technical.
- jstimpfle 4y agoTypical statement coming from people lacking experience in this field (no offense meant). The truth is, parsing strings in C is as easy as in any other language. You have a string array and a length field, and you scrub through it from left to right with a cursor. Done. What you do not get in C is creating lots of string objects willy-nilly, and concatenating them with a plus sign, like you do in scripting languages.