TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

C++17’s useful features for embedded systems

218 点作者 manchoz将近 2 年前

14 条评论

WalterBright将近 2 年前
I added 0b binary literals to C++ back in the 1980s.<p><a href="https:&#x2F;&#x2F;www.digitalmars.com&#x2F;ctg&#x2F;ctgLanguageImplementation.html#binary_constants" rel="nofollow">https:&#x2F;&#x2F;www.digitalmars.com&#x2F;ctg&#x2F;ctgLanguageImplementation.ht...</a>
评论 #36120022 未加载
jrmg将近 2 年前
I had some fun recently using (abusing?) `constexpr` to process string literals at compile time to ‘compress’ then in the binary and save a few bytes in my microcontroller.<p><a href="https:&#x2F;&#x2F;gist.github.com&#x2F;th-in-gs&#x2F;7f2104440aa02dd36264ed6bc38ce553#file-packedstrings-h" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;th-in-gs&#x2F;7f2104440aa02dd36264ed6bc38...</a><p>I’m just shaving some bits off - but I guess in principle you could do anything that’s `constexpr` evaluatable. Gzip compression of static buffers?…<p>Godbolt example:<p><a href="https:&#x2F;&#x2F;godbolt.org&#x2F;z&#x2F;qc7jhKoGc" rel="nofollow">https:&#x2F;&#x2F;godbolt.org&#x2F;z&#x2F;qc7jhKoGc</a>
评论 #36116598 未加载
评论 #36119850 未加载
评论 #36130771 未加载
评论 #36118323 未加载
kramerger将近 2 年前
Why<p><pre><code> uint8_t b = 0b1111&#x27;1111; </code></pre> I would rather have<p><pre><code> uint8_t b = 0b1111_1111; </code></pre> This &#x27; thing is hard to get right on some non-us keyboards. And yes, I&#x27;ve the same problem with Rust.
评论 #36116425 未加载
评论 #36119193 未加载
评论 #36115968 未加载
评论 #36119482 未加载
评论 #36128390 未加载
cmrdporcupine将近 2 年前
In-line class static variables ... finally.<p>if constexpr is neat (along with a bunch of the other constexpr&#x2F;compile-time features that have been coming along), but I feel like this will have both... good and bad uses, and I fear for the astronauts who will go crazy with this.<p>The enhanced conditionals, this I kind of like though it would take some while to get used to... kind of surprised this got in, being such a departure from C.<p>Small thing: hardware_destructive_interference_size is nice. Wish I had this in Rust.<p>Looks like it was asked for (<a href="https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rfcs&#x2F;issues&#x2F;1756">https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rfcs&#x2F;issues&#x2F;1756</a>) but went nowhere.
评论 #36115369 未加载
评论 #36115379 未加载
smarx007将近 2 年前
Isn’t polymorphic memory allocator the most significant recent C++ addition for embedded systems that allows preventing runtime memory allocation after the init phase and thus allows conformity to MISRA and other guidelines for critical SW development (esp. when using stdlib)?
评论 #36115428 未加载
评论 #36117845 未加载
keithnz将近 2 年前
Not really sure they are that useful for embedded systems. I think the most useful thing is in 20, and that is coroutines. For bare metal embedded systems this simplifies a lot of things. But isn&#x27;t super common on embedded toolchains yet.
评论 #36119902 未加载
评论 #36119811 未加载
c7DJTLrn将近 2 年前
Not a C++ developer but nodiscard is gross in my opinion. I&#x27;ve seen codebases littered with it for no good reason. Why should you care if the caller uses the return value or not?
评论 #36118275 未加载
评论 #36118718 未加载
评论 #36119964 未加载
评论 #36118910 未加载
评论 #36118621 未加载
评论 #36119497 未加载
评论 #36120712 未加载
评论 #36118291 未加载
评论 #36120038 未加载
评论 #36118493 未加载
alphanullmeric将近 2 年前
Hey rust - check it out. Compile time evaluation without macros, isn’t that neat?
评论 #36116176 未加载
评论 #36119021 未加载
mhh__将近 2 年前
Wrt hardware_destructive_interference_size, what happens if you compile for X86 which is then run on a machine (Rosetta) that has a (2x) bigger cacheline internally?
评论 #36115064 未加载
评论 #36115162 未加载
评论 #36115035 未加载
shadowgovt将近 2 年前
So much of modern c++ is trying to get around just using the preprocessor.
评论 #36115347 未加载
评论 #36119011 未加载
评论 #36115351 未加载
评论 #36116901 未加载
mhh__将近 2 年前
`if constexpr` is such a disaster. They were so close to getting it right (not introducing a scope) but they missed.<p>Similarly constexpr itself is also genuinely ridiculous: (I have said this on hackernews before) It&#x27;s such a stupid idea to require an annotation everywhere you want to evaluate things at compile time, practically everything will inevitably be evaluatable at compile time, and you need the implementation anyway, so just let it fail rather than ask for permission everywhere.<p>Having the keyword for variables and constants is fine (i.e. top down and bottom up constraints need to be dictated) but you shouldn&#x27;t need to write constexpr more than that.
评论 #36115365 未加载
评论 #36115082 未加载
评论 #36115442 未加载
评论 #36115565 未加载
评论 #36115401 未加载
评论 #36118055 未加载
评论 #36125015 未加载
评论 #36115089 未加载
评论 #36121793 未加载
评论 #36115318 未加载
tonetheman将近 2 年前
What compiler is he&#x2F;she using? I cannot get this to compile at all but I might not know the magic compiler incantation to get it to work.<p><pre><code> template&lt;typename T&gt; auto length(const T&amp; value) noexcept { if constexpr (std::integral&lt;T&gt;::value) { &#x2F;&#x2F; is number return value; } else { return value.length(); } }</code></pre>
评论 #36116974 未加载
评论 #36118685 未加载
评论 #36118943 未加载
评论 #36117532 未加载
swader999将近 2 年前
I&#x27;m sure other languages would have more than 17 useful features.
评论 #36115652 未加载
nuancebydefault将近 2 年前
The whole discussion about constexpr (even though a useful feature), is one example, out of many, of what a f up language C++ is&#x2F;has become. It&#x27;s astonishing how many people have to say... I don&#x27;t like the language but there&#x27;s no good alternative for the context we are working in.
评论 #36117714 未加载
评论 #36117826 未加载
评论 #36117806 未加载
评论 #36118325 未加载
评论 #36118898 未加载
评论 #36116979 未加载