5 ms·
Perhaps for Android, but I'm hesitant about using Clang for Win64 due to some recent bugs (such as tellg not working correctly).
by jdlyga 11y ago
Perhaps for Android, but I'm hesitant about using Clang for Win64 due to some recent bugs (such as tellg not working correctly).
- AlexeyBrin 11y agoNDK is only for Android (as in a C++ toolchain for Android, the toolchain runs on Windows, Linux and Mac but the resulting executables are meant for Android) ... what do you mean with Win64 in this context ?
- xd1936 11y agoHe probably meant the x64 compiler on Windows. From the link: "Also note that Clang packaged in the Windows 64 NDK is actually 32-bit."
- klodolph 11y agoThat's probably a bug in libc++, not Clang. They're under the same roof, but different people work on them. Also, I would mock you for using <iostream> at all but you've probably got legacy code just the same as I do.
- Buge 11y agoI'm curious, what's wrong with iostream?
- duaneb 11y agoI dunno, I think bit shifting a string to write to a file is pretty unreadable, not to mention C already has rock-solid string formatting options. It's an miasma of operator abuse built into "hello world".
- GFK_of_xmaspast 11y ago> C already has rock-solid string formatting options Don't troll.
- duaneb 11y agoDo you have an actual response? How is iostream any better than *printf? At least you can read the format of the former without needing to google un-googleable operators.
- msbarnett 11y ago> How is iostream any better than *printf? Type checking.
- duaneb 11y agoYou already have to do odd casting to get around compiler warnings when passing invalid types to a format—I don't buy this anymore.
- simoncion 11y ago> I don't buy this anymore. You should: https://news.ycombinator.com/item?id=10775022 https://news.ycombinator.com/item?id=10775022
- jmgao 11y agoprintf has type checking in every major compiler. You just need to annotate all of your printf-y functions with attributes to tell the compiler "this function does printf, the format string is the nth argument, and the format arguments start at the mth argument". It doesn't work with non-constexpr format strings, but there aren't many justifications for those.
- simoncion 11y ago> How is iostream any better than [<star>]printf? What consistent mechanism do you use to printf an instance of an arbitrary user-defined type? With ostream, you implement ostream& operator<<(ostream&, const Class&) and you're done. with printf, you have to have a convention and remember to stick to it. (Do I call .toString(), .stringize(), .getString()... ??) For one-off things, printf is great. You take it from me when you pry it from my goddamn cold, dead, hands. However, for real work io*stream are rather nice.
- simoncion 11y ago> ...I think bit shifting a string to write to a file is pretty unreadable... If you have a fundamental misunderstanding of the meaning of an operator, it's pretty easy to fail to correctly read a section of code. Maybe you're someone who hates operator overloading. If so, that's a pity. It's a useful power tool. [0] [0] Yes, all power tools can be abused. That conversation is tired and not worth revisiting.
- cbd1984 11y agoHow do you internationalize strings built up from multiple string fragments?
- endgame 11y agoLink for those who need more context: http://yosefk.com/c++fqa/web-vs-c++.html#misfeature-4 http://yosefk.com/c++fqa/web-vs-c++.html#misfeature-4
- simoncion 11y agoThe same way you'd do it in printf? Stringize data and insert it in the middle of static text? (Pardon my inelegant code, I've been away from C++ and doing Erlang for quite a while now.) void printStuff(ostream Os, string WarningPart, string SizePart, string EndPart, int Size) { //The English version might look like: //"Warning: Size too big (200). Get smaller." Os << WarningPart << SizePart << Size << EndPart << endl; }; I expect that if I thought about the problem for a few minutes (and was unable to find any C++ i18n libraries) I would come up with something much nicer and easier to use than this thing I spent ten seconds working on. :)
- prodigal_erik 11y agoPOSIX printf allows a translator to write a conversion spec like "%1$d" that says which arg to print. This lets you do stuff like put currency before or after the amount depending on what's idiomatic for the locale, without recompiling (if you lookup your format strings at runtime).
- simoncion 11y agoSure, but that's l10n, which is a different -but related- thing. :) printf format strings are well thought-out. I was demonstrating that the same ideas can easily be used with io*stream.
- simoncion 11y agoFor the downvoters: Here's a lib that accomplishes this task that's had a fair bit more than 10 seconds of thought put into it: [0]. Examples [1][2]. :) [0] http://www.boost.org/doc/libs/1_60_0/libs/locale/doc/html/index.html http://www.boost.org/doc/libs/1_60_0/libs/locale/doc/html/in... [1] http://www.boost.org/doc/libs/1_60_0/libs/locale/doc/html/hello_8cpp-example.html http://www.boost.org/doc/libs/1_60_0/libs/locale/doc/html/he... [2] http://www.boost.org/doc/libs/1_60_0/libs/locale/doc/html/messages_formatting.html http://www.boost.org/doc/libs/1_60_0/libs/locale/doc/html/me...
- ambrice 11y agoIt's a pain to format text. Things like: printing an int in hex, printing a zero-padded int of a specific length, printing a float to two decimal places. And having those formatting changes be stored silently as global state leads to unexpected behavior.
- saurik 11y agoFWIW, most of these options revert back to default as soon as you format something; but I agree that I would have preferred iomanip to generally be a wrapper around values rather than a silent modifier of the stream.