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.

22nd Century C

130 pointsby Proceduralover 8 years ago

16 comments

miekoover 8 years ago
I&#x27;ve spent two decades writing C and C++, but the last 8-9 years in really high-level languages (Ruby, Javascript, Python). From either end of the spectrum, I&#x27;ve never felt the need for such emphasis on fixed-sized numeric types.<p>I&#x27;ve commonly needed <i>access to</i> fixed size numerics, like when sending texture formats to the GPU, defining struct layout in file formats and network protocols, but I have never once thought: &quot;You know what, I&#x27;d like to make a decision as to the width of an integer every time I declare a function.&quot;<p>&quot;Just has to work&quot; low level code was the norm during the 16-bit to 32-bit transition, so it was a fucking pain. Notice how smooth the 32-bit to 64-bit transition went? (and yes, it was smooth.) I credit that to high-level languages that don&#x27;t care about this stuff, and people using better practices like generic word-sized ints and size_t&#x27;s in lower level code. Keep that stuff on the borders of the application.<p>I&#x27;ve noticed a decent-sized emphasis on type size in both Crystal and Swift, two not-entirely braindead newer languages. I don&#x27;t get it, it&#x27;s a big step backward.
评论 #12472299 未加载
评论 #12473135 未加载
评论 #12472025 未加载
评论 #12472864 未加载
评论 #12472400 未加载
评论 #12472573 未加载
评论 #12473587 未加载
评论 #12472357 未加载
评论 #12473942 未加载
评论 #12474310 未加载
cpercivaover 8 years ago
You can write C in any language. You can also write any language in C.<p>The fact that it&#x27;s possible does not imply that it&#x27;s a good idea. Some of the macros here are in common use (e.g., countof, although often with other names); some will make experienced C developers say &quot;what&#x27;s this? Oh, you mean &lt;insert expansion here&gt;; why did you use a weird macro?&quot;; and some, like the redefinitions of <i>case</i> and <i>default</i> are actively hostile and are guaranteed to result in bugs when exposed to experienced C developers.<p>For more of the same, see &quot;things to commit just before leaving your job&quot;: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;aras-p&#x2F;6224951" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;aras-p&#x2F;6224951</a>
generic_userover 8 years ago
I&#x27;m not sure that &#x27;address&#x27; is desirable.<p><pre><code> int adress adress adress foo;</code></pre> vs<p><pre><code> int * * * foo; </code></pre> Double pointers are extremely common and triple pointers show up now and then.<p>Also &#x27;__attribute__ cleanup&#x27; as far as I know only works with automatic variables that live on the stack. Mucking about with code execution and automatic variables as the stack unwinds is not a style I would like to see in general purpose C coding. Its the one type of automatic memory management that you get for free and can&#x27;t really screw up.<p>The rest of the macro loops and so forth seem fairly standard. Its good to experiment and explore what you can do with the compiler and the preprocessor.
评论 #12471984 未加载
dikaiosuneover 8 years ago
<p><pre><code> fn main() { println!(&quot;hello, world&quot;); } </code></pre> I kid, I kid. This looks cool!
alxmdevover 8 years ago
Very cool! I wasn&#x27;t aware of the cleanup attribute, can&#x27;t wait to try it out:<p><i>The cleanup attribute runs a function when the variable goes out of scope. This attribute can only be applied to auto function scope variables; it may not be applied to parameters or variables with static storage duration. The function must take one parameter, a pointer to a type compatible with the variable. The return value of the function (if any) is ignored.</i><p><a href="https:&#x2F;&#x2F;gcc.gnu.org&#x2F;onlinedocs&#x2F;gcc&#x2F;Common-Variable-Attributes.html" rel="nofollow">https:&#x2F;&#x2F;gcc.gnu.org&#x2F;onlinedocs&#x2F;gcc&#x2F;Common-Variable-Attribute...</a>
评论 #12473122 未加载
microcolonelover 8 years ago
The &quot;case&quot; and &quot;default&quot; overrides seem kinda dicey.
评论 #12472185 未加载
评论 #12472442 未加载
评论 #12473846 未加载
em3rgent0rdrover 8 years ago
I don&#x27;t get it. Could someone summarize&#x2F;explain this.
评论 #12471855 未加载
评论 #12471851 未加载
jdmoreiraover 8 years ago
Maybe the author wanted this to be C99 compliant but a cool thing is that by using clang we even have lambdas. It&#x27;s called blocks, the same as in Objective-C. <a href="http:&#x2F;&#x2F;clang.llvm.org&#x2F;docs&#x2F;BlockLanguageSpec.html" rel="nofollow">http:&#x2F;&#x2F;clang.llvm.org&#x2F;docs&#x2F;BlockLanguageSpec.html</a><p>I&#x27;ve been using them in all my new C code, since I&#x27;m stuck to clang anyway, and it&#x27;s awesome.
TickleSteveover 8 years ago
this is basically an updated version of iso646.h<p>[<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;C_alternative_tokens" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;C_alternative_tokens</a>]<p>...and no, they&#x27;re not a good idea, its just a syntactic change. If you want a &#x27;better-C&#x27;, language-wise, Rust is pretty much best current hope, tho that wont mature for another decade or so.
评论 #12473623 未加载
transfireover 8 years ago
Still using header files in the 22nd century?
n_yuichiover 8 years ago
It reminds me of libCello<p><a href="http:&#x2F;&#x2F;libcello.org" rel="nofollow">http:&#x2F;&#x2F;libcello.org</a>
dpc_pwover 8 years ago
That is very impressive. I really like the cleverness and cleanliness of these &quot;hacks&quot;.<p>Still... I wouldn&#x27;t introduce it into existing&#x2F;shared codebase due to risk of confusing everyone, and I will never start my own project in C again.
jagger11over 8 years ago
I wonder if this is in any way inspired by this - <a href="https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;honggfuzz&#x2F;blob&#x2F;master&#x2F;common.h" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;honggfuzz&#x2F;blob&#x2F;master&#x2F;common.h</a> ?<p>I use there defer for both gcc&#x2F;clang, countof(arr) -&gt; ARRAYSIZE(array)<p>In any case, yeah, going through gcc&#x2F;clang internals, and through C11 standards gives people some ways to speed-up and clena-up their implementations a bit.
catb0tover 8 years ago
It looks like just a cross between Go, DLang and maybe something else. Maybe I&#x27;ll use it to troll my programming teacher.
approachingtrajover 8 years ago
This is so fucking stupid.
Mathnerd314over 8 years ago
Too little too late. Rust is already taking over, by the 22nd century C will be dead.
评论 #12472143 未加载
评论 #12472345 未加载
评论 #12472716 未加载