News for hackers. Stuff that matters.
Re:C++23: The Next C++ Standard by tialaramex on Tuesday July 11, 2023 @07:00PM (#36688364)
> Code calling printf() with a constant format string literal is this class of code that you have to run a single time to know it works

    void msg(char *msg, char *x, int k) {
        printf("%hhn%s%d\n", x, msg, k);
    }
So, how about it? I mean, I have code where that works exactly as expected, so I can "know it works" according to you, but I also have code where that blows up immediately, because it's complete nonsense. Which according to you shouldn't happen, but there it is.
Re:C++23: The Next C++ Standard by jstimpfle on Tuesday July 11, 2023 @07:08PM (#36688409)
I mean yes, I should have been more restrive in my statement, but I'm sure you notice how we're veering more into the hypothetical / into programming language geek land. I had to literally look up %hhn because I've never used it.

(Have used %n years ago but noticed it's a fancy and unergonomic way to code anyway. Use snprintf()!)

And btw. how is this a problem related to missing type checks with varargs? The only problem I see is that we don't know that those pointers are not null / the char-pointer doesn't point to a zero-terminated string. In other words, just the basic C level of type (un)safety

Re:C++23: The Next C++ Standard by xeyownt on Wednesday July 12, 2023 @04:55AM (#36691979)
Totally agree, given example is total nonsense.

Most issues with printf could be reported by static analysis, and modern compiler reports them as warnings, which in my book must be immediately converted to errors. All other weird usages should be either banned, or reviewed carefully, but they are very rare.

Also, std::iostream is ridden with bugs as well. Try to print out hex / dec in a consistent way is plain "impossible". Everytime you print an int, you should in fact systematically specify the padding, alignment and mode (hex/dec) otherwise you can't know for sure what you are outputting.

Re:C++23: The Next C++ Standard by qalmakka on Wednesday July 12, 2023 @07:38AM (#36693060)
iostream _sucks_, I had to implement an iostream for zlib + DEFLATE in order to play ball with an iostream-based library, and I had to sweat blood and tears in order to make it work right when a simple loop and a bit of templated code would have worked wonders compared to that sheer insanity of `gptr`, `pubsync`, ... The moment you notice that they've methods called "pubXXX" that call a protected "XXX" on the `basic_streambuf` class is the moment your soul leaves your body.

IOStreams is superbad, and thankfully <format> removes half of its usages which were based on spamming `stringstream`s everywhere (stringstream is also very, very bad). They also inspired Java's InputStream nonsense which ruined the existence of an innumerable number of developers in the last 30 years.

Re:C++23: The Next C++ Standard by throwaway2037 on Wednesday July 12, 2023 @12:05AM (#36690347)
This is an interesting post. Can you explain the two different scenarios with examples?