Made In Chelsea fans left in shock as it's revealed Alex Mytton's model ex is having a baby with Issy Francis-Baum's father
Inside Britain's fattest town where women die early and KEBABS are the healthy option: It boasts 87 takeaways, breakfast sausage rolls and a bed-shop that caters to 37st people. Now there's a glimmer of hope...
Jaecoo's UK boss reveals how £29,000 SUV is wooing the Range Rover set
Trump reveals 'desperate' Iran wants nuclear weapon after failed peace talks and claims he 'doesn't care' whether Tehran comes back to negotiating table
The 'horrific' 60 Minute Makeover that was banned from airing after devastated widower left furious by ITV crew destroying his late wife's beloved furniture
No Doubt guitarist Tom Dumont, 58, reveals Parkinson's diagnosis as he says 'it's been a struggle every day'
First-time buyers have paid QUADRUPLE the amount of stamp duty since tax break ended
STEPHEN GLOVER: Trump has finally forced Starmer to freeze his shameful Chagos deal. Now the PM must dump it in the bin - for ever
France’s digital directorate dumping Windows desktops, adopting Linux instead
France’s Interministerial Directorate for Digital Affairs (DINUM) will drop Windows desktops, and adopt Linux instead.…
Tearful father tells of moment he found his daughter, 19, dead at home 'after family dog attacked her'
Gemma Collins and Sinitta's I'm A Celeb feud rages on with social media swipe days after GC's foul-mouthed rant about being branded a 'joke'
Oil prices spike as Trump plans his own clampdown on Strait of Hormuz and blasts NATO for not helping to defeat Iran: 'They weren't there for us'
Anthropic Asks Christian Leaders for Help Steering Claude's Spiritual Development
Read more of this story at Slashdot.
IT manager approved downtime over lunch, but made a meal of it
Who, Me? The best part of the working day is lunchtime, but The Register tries to start Mondays in a pleasant fashion by bringing you a new installment of "Who, Me?" – the reader-contributed column in which you admit to your mistakes and detail your escapes.…
CodeSOD: Non-cogito Ergo c_str
Tim (previously) supports a relatively ancient C++ application. And that creates some interesting conundrums, as the way you wrote C++ in 2003 is not the way you would write it even a few years later. The standard matured quickly.
Way back in 2003, it was still common to use C-style strings, instead of the C++ std::string type. It seems silly, but people had Strong Opinions™ about using standard library types, and much of your C++ code was probably interacting with C libraries, so yeah, C-strings stuck around for a long time.
For Tim's company, however, the migration away from C-strings was in 2007.
So they wrote this:
if( ! strncmp( pdf->symTabName().c_str(), prefix.c_str(), strlen( prefix.c_str() ) ) ) { // do stuff }This is doing a "starts with" check. strncmp, strlen are both functions which operate on C-strings. So we compare the symTabName against the prefix, but only look at as many characters as are in the prefix. As is common, strncmp returns 0 if the two strings are equal, so we negate that to say "if the symTabName starts with prefix, do stuff".
In C code, this is very much how you would do this, though you might contemplate turning it into a function. Though maybe not.
In C++, in 2007, you do not have a built-in starts_with function- you have to wait until the C++20 standard for that- but you have some string handling functions which could make this more clear. As Tim points out, the "correct" answer is: if(pdf->symTabName().find(prefix) != 0UL). It's more readable, it doesn't involve poking around with char*s, and also isn't spamming that extra whitespace between every parenthesis and operator.
Tim writes: "String handling in C++ is pretty terrible, but it doesn't have to be this terrible."