- 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....
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?
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.
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 = .
Admin
Thank you Steve, I did not know about constexpr. A nice addition to the toolbox.
In this instance a simple const would also have worked.
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"....
Admin
... err, that's a logical OR not bitwise...
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.
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.
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.
Admin
Ehm... sometimes, one wants to correctly set ALL of the bits (because the other ones also may -and often do- have a meaning). Sometimes, instead, a code that just "works by chance" is enough. It depends on the expectations...
Admin
People need to call it "decimal" more often. When people talk about base "10" it only mean base ten if... you're already using base ten...
Admin
Yes sometimes you do and othertimes other bits are irrelevant, but whatever the case you don't go and hardcode bitmasks all over the code like that.
Real WTFs in order of precedence:
Not-A-WTFs:
Admin
Wooooosh!
The sound of the joke sailing over your head :-)
Admin
If you were replying to me, see my answer to Anon E Mus.