Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Spurious diagnostic messages |
| Date | 2015-09-26 15:33 -0700 |
| Organization | None to speak of |
| Message-ID | <lnk2rc95f3.fsf@kst-u.example.com> (permalink) |
| References | (13 earlier) <ln1tfljs4u.fsf@kst-u.example.com> <d27fk4F55b9U4@mid.individual.net> <kfnpp2cy38e.fsf@x-alumni2.alumni.caltech.edu> <d41c4gFmnsqU1@mid.individual.net> <kfnh9mhgrzn.fsf@x-alumni2.alumni.caltech.edu> |
Tim Rentsch <txr@alumni.caltech.edu> 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 <http://www.ghoti.net/~kst>
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"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Spurious diagnostic messages Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-26 07:44 -0700
Re: Spurious diagnostic messages Keith Thompson <kst-u@mib.org> - 2015-09-26 15:33 -0700
Re: Spurious diagnostic messages Gareth Owen <gwowen@gmail.com> - 2015-09-28 19:57 +0100
Re: Spurious diagnostic messages Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-28 20:52 +0100
Re: Spurious diagnostic messages Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-09-29 11:19 +0000
Re: Spurious diagnostic messages glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-09-28 22:26 +0000
Re: Spurious diagnostic messages Bartc <bc@freeuk.com> - 2015-09-30 13:56 +0100
Re: Spurious diagnostic messages Gareth Owen <gwowen@gmail.com> - 2015-09-30 19:22 +0100
Re: Spurious diagnostic messages Bartc <bc@freeuk.com> - 2015-09-30 19:45 +0100
Re: Spurious diagnostic messages Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-04 09:02 -0700
Re: Spurious diagnostic messages Bartc <bc@freeuk.com> - 2015-10-04 18:34 +0100
Re: Spurious diagnostic messages Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-05 00:23 -0700
Re: Spurious diagnostic messages Keith Thompson <kst-u@mib.org> - 2015-10-04 15:56 -0700
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-04 20:04 -0700
Re: Spurious diagnostic messages Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-09 09:13 -0700
Re: Spurious diagnostic messages Keith Thompson <kst-u@mib.org> - 2015-10-09 13:40 -0700
Re: Spurious diagnostic messages David Brown <david.brown@hesbynett.no> - 2015-10-10 22:26 +0200
Re: Spurious diagnostic messages supercat@casperkitty.com - 2015-10-10 13:49 -0700
Re: Spurious diagnostic messages Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-14 07:53 -0700
Re: Spurious diagnostic messages Ian Collins <ian-news@hotmail.com> - 2015-09-27 17:30 +1300
Re: Spurious diagnostic messages Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-04 10:26 -0700
Re: Spurious diagnostic messages Ian Collins <ian-news@hotmail.com> - 2015-10-05 17:02 +1300
Re: Spurious diagnostic messages Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-09 10:06 -0700
csiph-web