Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's not even necessary for the compiler to do it: writing a type-safe wrapper is pretty easy in C++11 and a decent approximation is doable in pure C99 (ask me if you want a sample). Yet using the ugly PRI macros seems common even in C++ projects. It's understandable why one wouldn't want to use ostream type formatting, but at least write a better printf...

(Type-safe at runtime, that is, via automatically passing a type info argument along with each format argument; C++ is braindead enough that doing the check at compile time is only somewhat possible with C++14 - as far as I can tell, it only works if you define the format outside of a function - and probably fairly slow, since that involves a template instantiation per character in the format. Oh well.)



> and a decent approximation is doable in pure C99 (ask me if you want a sample).

I'd like to see that.

I can see some pretty straightforward ways to do it with C11 and _Generic, but I don't see how C99 helps.


With C++14 you don't need to define the format string outside functions, but it does get a little hairy. Here's a half-assed example: http://coliru.stacked-crooked.com/a/3f34563e9a85af51




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: