←back to thread

271 points mithcs | 2 comments | | HN request time: 0.415s | source
Show context
miroljub ◴[] No.45953073[source]
Nice toy. It works until it stops working. An experienced C developer would quickly find a bunch of corner cases where this just doesn't work.

Given how simple examples in this blog post are, I ask myself, why don't we already have something like that as a part of the standard instead of a bunch of one-off personal, bug-ridden implementations?

replies(2): >>45953149 #>>45953168 #
Borg3 ◴[] No.45953149[source]
Yeah, kids like to waste time to make C more safe or bring C++ features. If you need them, use C++ or different language. Those examples make code look ugly and you are right, the corner cases.

If you need to cleanup stuff on early return paths, use goto.. Its nothing wrong with it, jump to end when you do all the cleanup and return. Temporary buffers? if they arent big, dont be afraid to use static char buf[64]; No need to waste time for malloc() and free. They are big? preallocate early and reallocate or work on chunk sizes. Simple and effective.

replies(4): >>45953181 #>>45953199 #>>45953578 #>>45953726 #
1. lukan ◴[] No.45953181[source]
Can you share such a corner case?
replies(1): >>45958168 #
2. Borg3 ◴[] No.45958168[source]
No, because I did NOT do serious analisis of this. Nor I care, ask upper commenter.. C have some corner case and undefined behaviours and this stuff will make it worse IMO.