TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Modern C and What We Can Learn from It [video]

140 pointsby pmarinabout 4 years ago

10 comments

harry8about 4 years ago
Association of C and C++ Users (ACCU)<p>They should really just call themselves the ACU, they are wildly pro C++. It&#x27;s progress that there is even a C talk at all at their conference but even looking at the title it&#x27;s pitching itself at &quot;No really, C isn&#x27;t completely worthless&quot;<p>One day such language wars might seem quaint. While everyone has their livelihoods tied to their chosen technologies it probably won&#x27;t. C++ is fine imho fwiw. It&#x27;s just not anything like &quot;always and everywhere a better choice that C which should be treated as a virus.&quot;<p>The Scala folk are worst at it around here that I&#x27;ve seen but my experience may not be yours. People used to say similar of the LISP people on newsgroups. Perl was the first I saw where Larry and co. spent a lot of resource trying to make that not happen in the community. Python did a decent job following from what I&#x27;ve seen. C++ has always been pretty brutal in silly ways. I hope for it to calm down. Having one purely C talk at the conference of the Association of C and C++ users might be considered in some spheres to be &quot;progress of a sort.&quot;<p>edit: disclosure. I am a member of the ACCU.
评论 #27073170 未加载
评论 #27074526 未加载
评论 #27073219 未加载
throwaway20014about 4 years ago
Anyone who wants a very good modern C book that&#x27;s only 272 pages, take a look at &#x27;Effective C - An Introduction to Professional C Programming by Robert C. Seacord. [1]. It&#x27;s from 2020.<p>Robert Seacord is a Technical Director at NCC Group where he develops and delivers secure coding training in C, C++, and other languages. Seacord is an expert on the C Standards committee. &gt; That&#x27;s some solid credentials. He focuses on secure C code in the book.<p>Here&#x27;s a short article on why he wrote the book [2].<p>[1] <a href="https:&#x2F;&#x2F;nostarch.com&#x2F;Effective_C" rel="nofollow">https:&#x2F;&#x2F;nostarch.com&#x2F;Effective_C</a><p>[2] <a href="https:&#x2F;&#x2F;ieeexplore.ieee.org&#x2F;document&#x2F;9237323" rel="nofollow">https:&#x2F;&#x2F;ieeexplore.ieee.org&#x2F;document&#x2F;9237323</a>
评论 #27076118 未加载
评论 #27074165 未加载
Arnavionabout 4 years ago
The presenter has discovered the Result &#x2F; Either monad at 00:24:16, but their proposed C implementation sounds like a really bad idea:<p>- The flag needs to be manually inlined into every type, thus bloating the type even after the value has been successfully created. ie every instance of `file_contents_t` in your program has become the equivalent of `Result&lt;file_contents_t&gt;` and you have to check it for validity every time you use it, not just when you create it.<p>- The flag is easy to forget to check. `std::optional` has that problem too with its `*` and `-&gt;` operators, but at least you have to write them, as well as the type &quot;std::optional&quot;, explicitly. You can&#x27;t accidentally use a `std::optional&lt;file_contents_t&gt;` as a `file_contents_t`, but you can accidentally use a `file_contents_t` with `.valid = false` where one with `.valid = true` was expected.<p>- The `img = crop_to_cat(img); img = add_bow_tie(img); ...` example looks great when you just call the functions in sequence and expect each function to be a no-op for invalid inputs. But this breaks down when you have loops or logging or sleeps or other side effects that you genuinely want to skip. At that point you will have to start checking `if (img.valid)` manually again anyway. And if there are enough of these scattered around multiple scopes, you&#x27;ll end up wanting `goto error` again.<p>The callback-based example with `std::optional` as well as the Rust example with early returns don&#x27;t have these problems. (Incidentally the Rust version uses an explicit `match` and manual return of the error for some reason, even though that particular usage pattern is exactly what the `?` operator is for.)
评论 #27072841 未加载
评论 #27076045 未加载
评论 #27072795 未加载
jhaurisabout 4 years ago
As a professional C++ programmer who hasn&#x27;t used C since the compiler limited me to C89 (so 2015ish), I am very impressed by how clean C code can look these days. This was a great talk. There are a lot of really good things in modern C, and if I ever have to use C again I will have some great new tools. And I found the &quot;25k allocations for a single character entered&quot; in chrome extremely shocking; it definitely pays to think about allocations in C++.<p>Given the improvements, I found the warning <i>not</i> to use libc unless absolutely necessary very surprising. I suppose C++ has parts we know to avoid, but I wonder why, with all the improvements to the C language, there haven&#x27;t been the same improvements to the standard library? It appears C programmers are used to rewriting pretty basic functionality for every new project, or carting around their personal utility library.<p>I&#x27;m also still not at all convinced by macros.
synergy20about 4 years ago
What I really want, is a C++ book that lists the absolutely must-have features for a beginner-intermediate programmer, I don&#x27;t want to be overloaded(no pun intended) with all those 2000 advanced features, I can read an advanced level book when I&#x27;m ready.<p>Basic types, smart-pointers(how to use them and when to use them), basic OOD and template(but no advanced tricks), essential algorithms and containers, that&#x27;s about them. No need on constexpr, rtii etc for now.<p>In this fast-paced world it&#x27;s hard to get interested in any books more than 300 pages for me.
评论 #27078359 未加载
评论 #27079095 未加载
squarefootabout 4 years ago
What book would you suggest for someone who started on the K&amp;R 2nd Ed. then didn&#x27;t write a line in C for about 15 years? I would appreciate something near the K&amp;R style, but updated with the latest changes to the language, security related caveats etc.
评论 #27075491 未加载
makapufabout 4 years ago
It is to be noted that designated struct initializers will be&#x2F;are in C++20 (of course it has all the features, it&#x27;s C++). See it here: <a href="https:&#x2F;&#x2F;en.cppreference.com&#x2F;w&#x2F;cpp&#x2F;language&#x2F;aggregate_initialization" rel="nofollow">https:&#x2F;&#x2F;en.cppreference.com&#x2F;w&#x2F;cpp&#x2F;language&#x2F;aggregate_initial...</a>
评论 #27073084 未加载
评论 #27073385 未加载
an1sotropyabout 4 years ago
An account of modern C should also note &lt;tgmath.h&gt;, which came with C99, and makes &quot;sin()&quot; and &quot;cos()&quot; do the right thing w.r.t. argument type (float, double, long double), something that has long been possible in Fortran. In C, this allows you to typedef a &quot;real&quot; type, set to either float or double at compile-time, in order to conveniently explore trade-offs associated with the different floating point precisions. The implementation of tgmath.h is an incredible hack though <a href="https:&#x2F;&#x2F;www.pixelstech.net&#x2F;article&#x2F;1324906407-The-ugliest-C-feature%3A-%3Ctgmath-h%3E" rel="nofollow">https:&#x2F;&#x2F;www.pixelstech.net&#x2F;article&#x2F;1324906407-The-ugliest-C-...</a>
评论 #27074883 未加载
ameliusabout 4 years ago
Is it possible to translate C into (unsafe) Rust while maintaining both human readability and link-level compatibility?
评论 #27074984 未加载
评论 #27076468 未加载
评论 #27076623 未加载
评论 #27077962 未加载
0xdeadbeefbabeabout 4 years ago
What is isize_t?
评论 #27105440 未加载