Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Spurious diagnostic messages Date: Sat, 26 Sep 2015 15:33:52 -0700 Organization: None to speak of Lines: 50 Message-ID: References: <874mn5ty3y.fsf@kst-u.example.com> <87egm8qis7.fsf@kst-u.example.com> <45crratneenjh9ktjt1l8ioskb7ehrr8e5@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="2117"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QnhKiSxoxyXPCAOR7u4Ic" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:bJCU4dKOL70Vmos9PkLYEbJp738= sha1:gKB7NcfFaQ8Fi66BCkX+P+NTcvA= Xref: csiph.com comp.lang.c:71235 Tim Rentsch writes: [...] > An important phrase in what I said is "that provides no > capability beyond what is fairly easily available otherwise". > The math stuff doesn't fall into this category, whereas > binary constants do. You assert that binary constants don't provide a capability that is fairly easily available othrwise. I disagree. The capability they provide is expressing bit patterns clearly. It could be argued that hexadecimal constants provide the same capabiility. If I see `0x56`, it's obvious to me at a glance that the bit pattern is `0b0101_0110` (I'll temporarily assume that we have underscores in constants as well). If I see `0xcd`, it takes me a moment to figure out that the bit pattern is `0b1100_1101`. That's just me, but I'm sure I'm not the only one. If I want to *clearly* express a bit pattern as an integer, a binary constant (if the language supports it) is in my opinion the best and clearest way to do it. If instead of `0b0101_0110`, I write something like `BIN(01010110)` or `BIN("0101_0110")`, I first have to be sure that the BIN() macro does what I think it does -- and I have to do that for each distinct implementation of such a macro (likely with different names and different restrictions). If a single consistent BIN macro can be propagated so it's used by any code I'm likely to deal with, that's great -- but that's not likely to happen unless it's in the standard. A while ago you presented a macro that does something similar. I don't remember just how you did it, and if I wanted to use it I'd have to search for your article and copy the code. (I recall it being quite clever -- and that's both a good thing and a bad thing.) Re-implementing it myself probably wouldn't be worth the effort; I'd probably just use hex constants, perhaps with a comment to show the bit pattern if needed. I suspect that implementing binary constants in a compiler would be *less* effort than re-implementing that macro. For gcc in particular, the effort would consist of disabling the warning that's currently issued in pedantic mode and updating the documentation. For compilers that don't already support binary constants, the existing code that handles hex constants can be largely re-used. -- 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"