Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: printf format specifier changes Date: Mon, 06 Jul 2015 23:01:48 -0700 Organization: None to speak of Lines: 44 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="14178"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19PVCWphCLDS+B7rf3LhOzO" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:Y2gPV9eARG9d5nQSHFh6ttk0Y7M= sha1:HnU5BkHzr8cICfwTj9uzKt4Rgug= Xref: csiph.com comp.lang.c:64833 Bartc writes: > On 06/07/2015 19:44, Richard Heathfield wrote: [...] > But the idea can be refined a bit more and it still couldn't be called a > mini-language. > >> There is prior art for an alternative system that allows precise format >> control without requiring you to work /quite/ so hard on the types - the >> iostream model used by C++. It may not be a good example, but it is at >> least a horrible warning. > > It looks awful. Tastes differ. Personally, I have no esthetic problem with C++'s use of overloaded >> and << operators for I/O; in that context, I just don't think of them as shifts, and they do visually indicate the direction in which the information flows. (The same technique couldn't be used in C without adding operator overloading to the language.) What I find annoying is that the constructs used to control formatting (setting precision, width, base, etc) *change the state of the stream*. In C, I can write: printf("x = 0x%x\n", x); to print a value in hexadecimal, and it doesn't affect the next thing I print. In C++, if I write: std::cout << "x = 0x" << std::hex << x << "\n"; then the next integer I print will be in hexadecimal -- and if there's a clean idiom to restore a stream to its previous state, I'm not familiar with it. If anybody designs a new formatted I/O system for C, please don't do that. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"