Giving C a superpower: custom header file (safe_c.h)
171–180 of 277 posts
Re: Giving C a superpower: custom header file (safe_c.h)
#172Earlier quoted context omitted.
I'd think a POSIX mutex--a standard API that I not only could implement anywhere, but which has already been implemented all over the place--is way more "cross platform" than use of atomics.
To lift things up a level: I think a language’s abstractions have failed if we even need to have a conversation around what “cross platform” really means :-)
Re: Giving C a superpower: custom header file (safe_c.h)
#173Earlier quoted context omitted.
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…
Can you share such a corner case?
Re: Giving C a superpower: custom header file (safe_c.h)
#174Earlier quoted context omitted.
I'd think a POSIX mutex--a standard API that I not only could implement anywhere, but which has already been implemented all over the place--is way more "cross platform" than use of atomics.
To lift things up a level: I think a language’s abstractions have failed if we even need to have a conversation around what “cross platform” really means :-)
Re: Giving C a superpower: custom header file (safe_c.h)
#175Re: Giving C a superpower: custom header file (safe_c.h)
#176Earlier quoted context omitted.
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…
> static char buf[64]; In a function? That makes the function not-threadsafe and the function itself stateful. There are places, where you want this, but I would refrain from doing that in the general case.
Re: Giving C a superpower: custom header file (safe_c.h)
#177Earlier quoted context omitted.
I think these threads attract people that write code for performance-critical use cases which explains the "cosmic horror" over pretty benign things. I agree though: most programs aren't going to be brought to their knees over some GC sweeps every so often.
Outside of hobbyist things, performance-critical code is the only responsible use case for a non-memory safe language like C in 2025, so of course it does. (Even that window is rapidly closing, though; languages like Rust and Swift can be better than C for perf-critical things because of the immutability guarantees.)
Re: Giving C a superpower: custom header file (safe_c.h)
#178Earlier quoted context omitted.
A simple pointer ownership model can achieve temporal memory safety, but I think to be convenient to use we may need lifetimes. I see no reason this could not be added to C.
A C with lifetimes would be nice, I agree. Would be awesome if someone did a study to see if it's actually achievable... Cyclone's approach was certainly not enough, and I think some sort of generics or a Hindley-Milner type system might be required to get it to work, otherwise lifetimes would become completely unusable.
Re: Giving C a superpower: custom header file (safe_c.h)
#179Earlier quoted context omitted.
RC is a GC method and the least efficient one.
It's the most predictable and has much less overhead than a moving collector.
The optimisatios needed to improve such scenarions, are akin to a poor man's tracing GC implementation.
Re: Giving C a superpower: custom header file (safe_c.h)
#180Earlier quoted context omitted.
Not really, only in the mind of haters.
Let's start with object construction. You think you're creating an object. The compiler thinks you're declaring a function. Widget w(); // I made a widget, right? RIGHT? Wrong. You just declared a function that takes no parameters and returns a Widget. The compiler looks at this line and thinks "Ah yes, clearly this person wants to forward-declare a function in the middle of their function body because that's a compl…
By the way, C auto now means the same as C++11 auto.