Darrell

7.8K posts

Darrell banner
Darrell

Darrell

@beached_whale

C++, computer science, electronics, oxford commas, and running (he/him) https://t.co/jZOJl4pGke @[email protected]

Katılım Ağustos 2009
685 Takip Edilen408 Takipçiler
Darrell
Darrell@beached_whale·
@andrew_leach @PierrePoilievre I mean, we don't elect parties in Canada and people should be ensuring the MP represents the riding. There's a very low chance any of these MP's will be re-elected if history is a tell. But really, why are they leaving the Conservative party should be the first question.
English
0
0
0
31
Andrew Leach 🇨🇦
Andrew Leach 🇨🇦@andrew_leach·
Only one MP was not elected in the general election or today's by-elections and, unless @PierrePoilievre has crossed the floor, the Carney Liberals did, in fact, do just this.
Andrew Leach 🇨🇦 tweet media
English
4
21
120
4.2K
Darrell
Darrell@beached_whale·
@xlrndo @ID_AA_Carmack There are a few ways to do this in C++. * There's ILLE int const x = [&] { if( cond ) return 1; return 2; }( ); * There is a type that is like optional but only allows setting once before an error
English
0
0
0
104
xlrndo
xlrndo@xlrndo·
I wish C++ had a kind of deferred const system where a variable did not have to be initialized at declaration as long as it was inited once and only once before use. For instance: const int x; if (cond) x = 1; else x = 2; You can do some of this with the ternary operator, but not with anything too complex.
English
11
0
37
29.5K
John Carmack
John Carmack@ID_AA_Carmack·
When I started working in python, I got lazy with “single assignment”, and I need to nudge myself about it. You should strive to never reassign or update a variable outside of true iterative calculations in loops. Having all the intermediate calculations still available is helpful in the debugger, and it avoids problems where you move a block of code and it silently uses a version of the variable that wasn’t what it originally had. In C/C++, making almost every variable const at initialization is good practice. I wish it was the default, and mutable was a keyword.
English
186
184
3.2K
300.4K
Darrell
Darrell@beached_whale·
@supahvee1234 @ETH_en We really really need to pull the bandaid on vector<bool> and just remove it, even if we make it an undefined specialization for a few years. It needs to go. Bring back Stepanov's name for it that was in the original STL prior to standardization.
English
0
0
7
1.1K
Vittorio Romeo
Vittorio Romeo@supahvee1234·
An ETH Zurich (@ETH_en) lecturer published a paper "proving" that C++ vector is 20x slower than C array: arxiv.org/pdf/2410.10022 He used `vector<bool>`, completely unaware that it is a dynamic bitset. Guess googling "vector<bool> slow" before publishing was too hard. 🤦 #cpp
English
76
109
1.8K
312.2K
Darrell
Darrell@beached_whale·
@seanbax technically this isn't std C++. C++ has exceptions.
English
0
0
1
34
Sean Baxter
Sean Baxter@seanbax·
But gcc does something different than this. Way too much unspecified stuff in C++.
English
3
0
22
1.6K
Sean Baxter
Sean Baxter@seanbax·
Oh, naturally. With -fno-exceptions, clang bans use of throw and try, *except in system headers*. i.e. if found with -isystem, you can use it. If found with -iquote, you can't.
Sean Baxter tweet media
English
2
3
52
6.1K
Darrell
Darrell@beached_whale·
@hankadusikova Not sure if joke or not, but I don't think that this is terrible. Like libstdc++ already has a path for hosts without threading. It would allow the same code to work, like shared_ptr in or put of constexpr
English
0
0
1
98
The Moisrex
The Moisrex@the_moisrex·
You just ruined switch-statements for me.
The Moisrex tweet media
English
78
139
1.8K
250.6K
Jason Turner
Jason Turner@lefticus·
@hankadusikova If someone doesn't stop me, I'm going to write my first paper, and it won't be about flat_* It will be to add `constexpr` to PMR. As it is you have to choose one or the other, you cannot write PMR friendly code that is also constexpr friendly.
English
3
0
18
1.8K
Darrell
Darrell@beached_whale·
@timur_audio i like the attribute syntax because it doesn’t look so similar to a declaration. Not sure that is helpful commentary though.
English
0
0
0
81
Timur Doumler
Timur Doumler@timur_audio·
For those who would like to see Contracts in C++26, but hate the attribute-like `[[ pre: ... ]]` syntax: Here's a counter-proposal with a much more natural looking syntax. open-std.org/jtc1/sc22/wg21… WDYT? Any feedback greatly appreciated.
Espoo, Suomi 🇫🇮 English
8
2
34
8.4K
Darrell
Darrell@beached_whale·
Interesting how the cost is 2x on Mac. For the longjmp the cost on Linux was 50ns, but others about 1us. So on most platforms the cost of the exception wasn't too bad, about 3-8x that of doing nothing(albeit on win lngjmp runs dtors, I think) 2/2
English
1
0
0
104
Darrell
Darrell@beached_whale·
Since adding configurable error handling to JSON Link, I did a test where I measured the cost in time of throwing an exception. It was interesting. As a base, I used lngjmp too but it is pretty much a noop(usually). One Linux/Windows the exception cost about 3-4us, Mac 8us 1/2
English
1
0
1
286
Darrell
Darrell@beached_whale·
@olafurw # pragma once is the litmus test for compilers I want to use. Also, it's better supported than std C++ with C++ compilers
English
0
0
4
273
Ólafur Waage
Ólafur Waage@olafurw·
Is pragma once standard? - No Supported in every major compiler? - Yup Then it's standard. - But... You wrote a piece of paper and the rest of the world disagrees with you. Accept defeat and move on.
English
6
9
156
22.9K
Andreas Fertig
Andreas Fertig@Andreas__Fertig·
In my latest blog post, "constexpr functions: optimization vs guarantee", you learn the power constexpr brings to your code. bit.ly/43AtWqK #cplusplus #cpp
English
4
6
33
3.3K
Darrell
Darrell@beached_whale·
@lefticus Not always free though, one can incur the cost of copying the default constructed object, whatever that is, but probably a memcpy in cost
English
1
0
1
323
Jason Turner
Jason Turner@lefticus·
Here's a fun discovery: by making the default constructor `consteval` on my new scripting engine, it *always* costs *0* to make a new instance of the scripting engine. That's infinitely faster start up than any other scripting engine I know of.
English
1
0
27
6.5K
Darrell
Darrell@beached_whale·
@kobi_ca Incentives. incentives, incentives :)
Català
0
0
1
11
Darrell
Darrell@beached_whale·
@SeamusBlackley This is how I am feeling, ill never repeat this streak and it is the only reason I am playing now.
English
0
0
0
56
Jason Turner
Jason Turner@lefticus·
@YehezkelShB @ben_deane Yeah, that's basically what Ben did for our JSON parser. For this code I'm more likely to just compile it to a bytecode at constexpr time, but we'll see.
English
1
0
1
44