Re: std::cout or printf
Posted: Wed Oct 31, 2018 8:58 pm
Am I the only one that happily uses std::cout without any problems? You can look at uci.cpp in RuyDos.
Probably because you Ctrl+V'ed it from Fruitcdani wrote: ↑Sun Oct 28, 2018 6:45 am I use this for Andscacs, I don't remember why:
Code: Select all
void afout(const char *fmt, ...) { va_list args; char buffer[4096]; va_start(args, fmt); vsprintf(buffer, fmt, args); va_end(args); fprintf(stdout, "%s", buffer); fflush(stdout); }
lucasart wrote: ↑Mon Nov 12, 2018 6:02 amProbably because you Ctrl+V'ed it from Fruitcdani wrote: ↑Sun Oct 28, 2018 6:45 am I use this for Andscacs, I don't remember why:
Code: Select all
void afout(const char *fmt, ...) { va_list args; char buffer[4096]; va_start(args, fmt); vsprintf(buffer, fmt, args); va_end(args); fprintf(stdout, "%s", buffer); fflush(stdout); }
This function is just equivalent to printf() + ffslush(). So you may as well replace it by a macro:
#define uci_printf(...) printf(__VA_ARGS__), fflush(stdout)
No need to build a string, and impose a 4096 byte limit.
Than you'd immediately stop using printf, because it's also a part or the C++ standard liblary, defined in header <cstdio>.Joost Buijs wrote: ↑Sat Oct 27, 2018 7:16 pmI try to avoid the std-library as much as possible, C++ has a lot of nice features but IMHO the std-library is not one of them. When you are using MSVC you can also use printf_s which is also more safe than printf.
You got it wrong, printf belongs to C runtime of course. cstdio is shitty wrapper which typically includes stdio.h internally,
This is typically the result of the "design by a committee" approach:mar wrote: ↑Tue Nov 13, 2018 2:22 pm cstdio is shitty wrapper which typically includes stdio.h internally,
no magic here except it injects these C functions into std namespace;
so (typically) you end up with std::printf and also printf in global namespace, you still typically get SEEK_SET as macros and so on.
So the <cxxxx> headers are not really useful at all and all you get is unnecessary clutter of std namespace, better use <stdio.h> directly.
I don't understand how this nonsense even made it into C++ standard, most likely someone got high.
Yes, well. I think anyone can write a proposal and it may/may not make it into the standard.lucasart wrote: ↑Wed Nov 14, 2018 12:24 am This is typically the result of the "design by a committee" approach:
* some idiot, who just discovered namespaces, and wet his pants dreaming about them says: hey this is awesome, we should encapsulate C library in a namespace too!
* someone else, likely the political kind, who knows it's a stupid idea, but doesn't want to say it to not offend the aforementioned idiot says: hum... ok, but let's not break backward compatibility, so we'll duplicate everything, with and without 'std::'.
Which is why good language design, and good design generally, can never result from committee decisions. The benevolent dictator approach is far superior, and avoids this kind of nonsense.
Even more, in some implementations std::cout itself is a wrapper over good old printf().mar wrote: ↑Tue Nov 13, 2018 2:22 pmYou got it wrong, printf belongs to C runtime of course. cstdio is shitty wrapper which typically includes stdio.h internally,
no magic here except it injects these C functions into std namespace;
so (typically) you end up with std::printf and also printf in global namespace, you still typically get SEEK_SET as macros and so on.
So the <cxxxx> headers are not really useful at all and all you get is unnecessary clutter of std namespace, better use <stdio.h> directly.
I don't understand how this nonsense even made it into C++ standard, most likely someone got high.