News for hackers. Stuff that matters.
Re:The Type of Sprintf by jznsis on Tuesday May 14, 2024 @10:35PM (#40362505)
This is just a choice of having to provide an output buffer to the function instead of returning a new buffer since it's easier to inject custom allocator behaviour that way
Re:The Type of Sprintf by anonymousiam on Tuesday May 14, 2024 @10:59PM (#40362632)
Can you elaborate please? Your description does not match what I see. My understanding is that this is a way to more strongly type function arguments, as an alternative to va_arg.
Re:The Type of Sprintf by jznsis on Tuesday May 14, 2024 @11:39PM (#40362859)
Yes, but the final result is out_str, not a forward to console, isn't it?

Either way, the format string discussion for the printf familiy of functions is very similar between them

Re:The Type of Sprintf by anonymousiam on Tuesday May 14, 2024 @11:46PM (#40362896)
Okay, got it. So you are agreeing with me that the author should have used printf instead of sprintf.

Thanks!

Re:The Type of Sprintf by jznsis on Wednesday May 15, 2024 @12:07AM (#40363003)
No
Re:The Type of Sprintf by jwilk on Wednesday May 15, 2024 @04:08AM (#40364313)
There's no return value here:

  void my_sprintf(char* format, ???) {
      sprintf(format, ???);
  }
Re:The Type of Sprintf by hoping1 on Wednesday May 15, 2024 @08:13PM (#40373875)
Author here, thanks for pointing that out! It was a mistake on my part (: I originally wrote this about printf, but decided I should include the section where I implement it, and I decided I didn't want to say anything about side effects, so I changed everything to a version that just returns the new string. In my head this is called "sprintf" (and the notes I based this on, linked in the post, did the same thing) though I can see now how this was confusing to people. Especially since I didn't rewrite it perfectly!