Re:Efficient string copying and concatenation in C
by segfaultbuserr on Thursday September 12, 2019 @12:57PM
(#20953712)
Exactly.
It's why call it "stupid", "insidious", but "somewhat relevant", as the parent comment proposes a better stdlib in C to handle strings.
Re:Efficient string copying and concatenation in C
by partialrecall on Thursday September 12, 2019 @01:49PM
(#20954267)
For some jobs, tolerance to tedium is considered a skill.
Re:Efficient string copying and concatenation in C
by jly on Thursday September 12, 2019 @05:01PM
(#20956418)
FizzBuzz covers a lot of (very basic) ground but adding memory manipulation is valuable. I ask a few simple string manipulation interview questions for embedded C developers as a weeder and the point is that we want to see how candidates deal with pointers and low level memory. There are other good follow-ups and alternatives you can build off this. Engineers with years of experience fail these questions all the time. Dealing with 'tedious' things like this is daily part of some developer jobs.
If I had to do something like that in a real program I'd very much overalloc a few bytes (because why not? If those small allocations really become a problem in your app you probably want to use a custom allocation scheme anyway) and then just snprintf the result into it. I'd go even further and say that code that would micro-optimize this to save a couple of bytes at the cost of maintainability shouldn't pass a code review IMO.