You're absolutely right of course; just about any facility's shortcomings can be overcome by redesigning that facility, but that's how we...
You're absolutely right of course; just about any facility's shortcomings can be overcome by redesigning that facility, but that's how we get Greenspun's Tenth Law. :) Unfortunately, redesigning for safety/correctness in C almost always means a loss of place-of-use conciseness. For example, you'd have to manually wrap each argument to your hypothetical printf replacement in a "struct type_wrapper." Plus, there's no way to enforce that your format string has the same number of placeholders as you have arguments. Speaking of which, you can actually do that in C++. It would look something like #include <cstddef> template <std::size_t N> static inline constexpr std::size_t num_args (const char (&fmt) [N]) { // Count args } template <std::size_t N, typename... Args> void printf2_impl (const char* fmt, Args&&... args) { static_assert (N == sizeof... (args), "Wrong number of arguments to printf2"); // Interleave args into fmt and print } #define printf2(fmt, ...) (printf2_impl <num_args (fmt)> (fmt, __VA_ARGS__)) You could even just typecheck the format string against your argument types and forward to printf. The biggest problem with this what happens when you give printf2 an empty __VA_ARGS__, but such is life when you're using the C preprocessor.
Posted by sjolsen on Mar 2, 2015, 9:02 AM
Tags
Related issues
- I mean that's the problem though.
- I've always believed the opposite: get conditionals deep in your code so that the higher level control flow is regular.
- The biggest problem with AI isn't being able to do things.
- I am a 3D printing maker type nerd (I make my own tools for other creative tasks, rather than as their own outcomes) and I saw an incredi...
- Of course not, those are clearly scams.
- Claude makes more detailed plans that seem better if you just skim them, but when analyzed, has a lot of errors, usually.
Raise real-world problems, find people facing the same issue, and discuss solutions.7,500 issues0 comments
hackernews (EdTech)
I mean that's the problem though.
I've always believed the opposite: get conditionals deep in your code so that the higher level control flow is regular.
The biggest problem with AI isn't being able to do things.
I am a 3D printing maker type nerd (I make my own tools for other creative tasks, rather than as their own outcomes) and I saw an incredi...
Of course not, those are clearly scams.
Claude makes more detailed plans that seem better if you just skim them, but when analyzed, has a lot of errors, usually.
Effectively everyone is building the same tools with zero quantitative benchmarks or evidence behind the why / ideas … this entire s...
> creating and operating a small company in Germany is a nightmare To be fair, I think the problem operating in Germany is its federated...
You're absolutely right of course; just about any facility's shortcomings can be overcome by redesigning that facility, but that's how we...
You're absolutely right of course; just about any facility's shortcomings can be overcome by redesigning that facility, but that's how we get Greenspun's Tenth Law. :) Unfortunately, redesigning for safety/correctness in C almost always means a loss of place-of-use conciseness. For example, you'd have to manually wrap each argument to your hypothetical printf replacement in a "struct type_wrapper." Plus, there's no way to enforce that your format string has the same number of placeholders as you have arguments. Speaking of which, you can actually do that in C++. It would look something like #include <cstddef> template <std::size_t N> static inline constexpr std::size_t num_args (const char (&fmt) [N]) { // Count args } template <std::size_t N, typename... Args> void printf2_impl (const char* fmt, Args&&... args) { static_assert (N == sizeof... (args), "Wrong number of arguments to printf2"); // Interleave args into fmt and print } #define printf2(fmt, ...) (printf2_impl <num_args (fmt)> (fmt, __VA_ARGS__)) You could even just typecheck the format string against your argument types and forward to printf. The biggest problem with this what happens when you give printf2 an empty __VA_ARGS__, but such is life when you're using the C preprocessor.
Comments (0)
No comments yet. Start the discussion.