- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
Use C++ - Binary literals since C++14....
Edit Admin
"The C Programming Language" is a really short book.
Admin
Was that spam comment let through because it's funny or because the spam filtering still doesn't work properly?
Edit Admin
I think I know who is next in line for promotion to upper management!
Admin
The C programming language bytes back.
Admin
If only there was some easy way to test whether this is true.
Admin
There's the real WTF right there: using #define. Should have used constexpr - then ~FLAG_A does exactly what it looks like it does.
Edit Admin
Did Remy edit the page? It has parentheses now.
constexpr
is new in C23.Admin
#define shouldn’t have an = .
Admin
#define shouldn’t have an = .
Edit Admin
I see there's much confusion about the
#define
with parentheses and equals signs or not.Here's how to do it properly:Plenty of parentheses in case they change operator precedence of
=
at some point and completely bug free. Not a single one.Admin
In Ada, 2#11# (the base can be 2 .. 16)
Admin
byte number = ((FLAG_A) || (FLAG_B))
(Usually) No: only one vertical bar (124dec) Also, I hope you know what you mean with "(byte) 10"....
Edit Admin
I've had more than one newbie trying to loop over an integer with a series of mods and divides to "get the binary representation of the number", when working with bit masks.
Admin
This post is bullshit. Decimal 11 = 8+ 2 + 1 meaning that lowest two bits were still correctly set if the goal was 0b11.
Furthermore, in 2024 you don't advise people to use #define for constants -- if you can #undefine it then it was never a constant to begin with.
Use a damn const int.
Edit Admin
"C doesn't have a standard way of specifying binary literals"
The 0b syntax is part of the proposed C23 standard. It's expected to get ISO's "rubber stamp" by the end of this year... So while that's a technically correct statement, you've only got a few weeks in which to keep saying it.
Edit Admin
Sorta.
The standard that matters is the standard that was in effect when the code was first committed from brain to keyboard.
Yeah, yeah, yeah, it's nice to go through your entire codebase every few weeks and update any/everything to the latest idioms, add testing and instrumentation, do a zero-based review of the code vs the specs & the user documentation, etc. But nobody does that.
The real danger is when the standard in use is the one in effect when the dev first learned to program by fiddling around in their parent's basement at home with some very different language from the one now being used.