News for hackers. Stuff that matters.
Re:C meeting is over. C23 added: by mungoman2 on Saturday February 19, 2022 @03:08AM (#30395292)
I can't tell if this is serious.

Surely if you're still using C now it's for legacy reasons. And if using it for legacy reasons you are likely stuck using an old C standard.

So who will use C23?

Re:C meeting is over. C23 added: by 10x-dev on Saturday February 19, 2022 @04:54AM (#30395801)
C is the best choice if you want all of: small (both language and binaries), fast (both compiler and binaries), obvious (no/minimal complex magic), close to the metal, with excellent debugging support, portability and integrations.

No other language has been battle tested for longer and more extensively than C.

Your kernels, OSes, drivers, databases, web servers and compilers are written in C.

If some of these features are not important to you, there are hundreds of slower, more complex and less portable languages to choose from, that provide other benefits instead, such as more convenience, more correctness and higher level abstractions.

Re:C meeting is over. C23 added: by kaba0 on Saturday February 19, 2022 @06:07AM (#30396179)
C isn’t that small, compare it to a Zig hello world. Fast is relative — due to C not having good expressive/abstracting powers, it will leave you to inferior solutions, eg. counting string length multiple times at call sites, vs C++’s small string optimization, which is simply not possible in a user-ergonomic way in C. Regarding obviousness, I would add UB here, so Zig for example would beat it.

C is not any closer to the metal than other system level programming languages, this myth should just die. Your code at -O3 gets mangled to oblivion, unless you are a compiler writer of the respective compiler, you will have no idea on the generated code. This is the exact same as with C++, Rust, etc, hell, C doesn’t have proper simd support, so in a way the former two is closer to the metal.

But I do agree on portability and integrations - so C will not die, but I really have a hard time seeing why should I choose C over any of the listed languages, unless I target some obscure CPU architecture.

Re:C meeting is over. C23 added: by 10x-dev on Saturday February 19, 2022 @06:43AM (#30396371)
Are you going to mix all those languages into one project and somehow use their advantages but steer away from their disadvantages?

Sure, other languages have caught up or have improved on some of the features where C shines.

Let's remove portability and integration from the feature list, because that's strongly related to C's tenure.

Which one of the languages you listed matches the rest of the feature set I brought up?

  * Small language
  * Fast compile times
  * Fast binaries
  * Small binaries
  * Great debugging experience
  * Close to the metal
In my opinion, they all fail in at least one category, and that's expected - additional functionality can't come for free. You can only accept its cost.
Re:C meeting is over. C23 added: by foxfluff on Saturday February 19, 2022 @08:59AM (#30397159)
And they fail in other categories too, e.g. C can be very terse whereas most modern so-called replacements tend towards verbose. For me that's a development exactly in the wrong direction; I'd rather have a more terse C.
Re:C meeting is over. C23 added: by xigoi on Saturday February 19, 2022 @01:19PM (#30399185)
Zig? I personally haven't used it, but based on what I've heard about it, it fulfills these criteria.
Re:C meeting is over. C23 added: by chaz72 on Saturday February 19, 2022 @04:09PM (#30400551)
That’s what I am betting on - but it isn’t 1.0 yet, and that matters too.
Re:C meeting is over. C23 added: by dzaima on Saturday February 19, 2022 @07:24AM (#30396609)
In C it's possible (and, to some level, very much encouraged) to write your own things to replace whatever built in thing you don't like for whatever reason, be it speed, size, portability.

C not having fancy built-in structures means programmers are more careful about choosing simple ones, which dramatically cuts down the amount of completely pointless generated code. -O3 can optimize registers and maybe memory reads/writes, but it can't remove reallocation from each call to a vector push, remove a reference count from a whole object type, or do pretty much anything with any moderately complex heap data structure. Sure, that comes at the cost of more advanced things being horrible to write, but it's a trade-off.

And I'll just disagree that UB must be unobvious. To me, it's one of the most useful optimization tools. You can check for it with sanitizers, and explicitly invoke it to convey information about hidden behavior to a compiler. It's not magic.

Re:C meeting is over. C23 added: by kaba0 on Saturday February 19, 2022 @10:59AM (#30398031)
> C not having fancy built-in structures means programmers are more careful about choosing simple ones

Resulting in linked lists everywhere which have pretty terrible performance characteristics. You should be worried about those way before the occasional vector push reallocation cause you any problem. (And you can specify initial capacity so there is that)

Re:C meeting is over. C23 added: by dzaima on Saturday February 19, 2022 @11:32AM (#30398311)
linked lists - true, but at least when you write them you'll be certain of what they do, and, coupled with knowledge of cache performance, precisely how bad they are. About reallocation I don't even mean the copying, but just the code needing to check for the chance overflow on every push. Besides the obvious waste of instructions to check for that, it also clobbers registers even if the branch isn't taken, and thus will easily result in a lot more unnecessary spilling to the stack. This kind of pointless thing happens in a ton of data structures.
Re:C meeting is over. C23 added: by kaba0 on Saturday February 19, 2022 @02:52PM (#30399935)
Branch prediction exists so the common case can be made very fast (much faster than jump to this remote pointer), and also, rust uses an optimizing compiler for a reason. Eg., you use a vector inside a for, the vector’s code can be inlined and the checking part be done only at the boundary. Also, one can also manually perform an unchecked push/get/whatever as well.
Re:C meeting is over. C23 added: by dzaima on Saturday February 19, 2022 @04:21PM (#30400647)
The common case may be fast, but it's still slower than not having a rare case in the first place. The untaken branch will still affect register allocation (out of the ~15 x86-64 general-purpose registers, only 5 (6 if you count rbp) preserve data after a non-inlined function call in the System-V ABI (of which there will be at least one, ending in malloc somewhere), and the compiler has to accommodate both taken and untaken at the branch end) and will eliminate any hope of SIMD vectorization, among other wrecked optimizations.

Unchecked operations are acceptable if your code has a single hot loop, but if you have a hundred small functions, each taking 1% of the time, you probably won't carefully examine every stdlib function each of them uses and write code to "work around" every unnecessary thing the stdlib does.

Yes, that's a ton of micro-optimization, but micro-optimization can bring a ton of speedup, so I'll take whatever makes it simpler (or not needed in the case where you already know what will happen due to having written it)

Re:C meeting is over. C23 added: by kaba0 on Saturday February 19, 2022 @05:48PM (#30401262)
Feel free to wrap it into a repr(transparent) type which exposes the unsafe operations by default.

But I seriously doubt that programs would benefit much from these micro-optimizations - there are rare and unfortunate cases where indeed there is no one single bottleneck for a program and thus there is no simple way to improve performance, but the vast majority of programs spend all their life in a tight hot loop, and anything else doesn’t matter in the slightest - hell, as mentioned C gets away with as many linked data structure as they want, but writing those in goddamn bash would suffice as well.

Re:C meeting is over. C23 added: by dzaima on Saturday February 19, 2022 @06:04PM (#30401372)
That depends on the project. There definitely are projects in which micro-optimizations such as this wouldn't be beneficial for one reason or another, but there definitely also are ones where they're make-or-break. For those, C is pretty good, and you're not fighting against the language (or the core intent of the language at least).

(I'd guesstimate that micro-optimizations would go a very long way in improving performance of nearly every program anywhere, but I don't have much data on that besides the couple projects where I've tried to care about performance, and having achieved pretty decent results)

Re:C meeting is over. C23 added: by deeviant on Sunday February 20, 2022 @01:09AM (#30403617)
I don't think I've ever used a linked list in 12 years of embedded C programming.
Re:C meeting is over. C23 added: by moralestapia on Saturday February 19, 2022 @10:31AM (#30397817)
>due to C not having good expressive/abstracting powers

I disagree, if anything, C's scantness forces you to abstract things much properly, unless you plan to write pages of boilerplate code here and there.

Re:C meeting is over. C23 added: by kaba0 on Saturday February 19, 2022 @05:39PM (#30401206)
With all due respect - how do you write a string library in C then? Char* is not one.
Re:C meeting is over. C23 added: by moralestapia on Sunday February 20, 2022 @01:25PM (#30407964)
An appropriate data type (you could use structs maybe) and methods for the common operations, concat, length, etc...

It's not as trivial "string s" like in other languages, but it's also not that big of a deal. Also, you make sure it works properly and you just use it anywhere you want.

Re:C meeting is over. C23 added: by WithinReason on Saturday February 19, 2022 @05:11AM (#30395892)
Languages exist that compile to C which gives them many of the above advantages and more, so why choose C over them?
Re:C meeting is over. C23 added: by 10x-dev on Saturday February 19, 2022 @06:12AM (#30396213)
Control over the code that actually runs.

We already lose quite a bit of control with C (e.g. it reorders your code as it pleases) to gain portability across CPUs, otherwise we'd have to rewrite the code in several assembly languages.

If you consciously choose to give up even more control over the code that runs (because a compiler that targets C necessarily adds another layer of autogenerated code that you don't control) then it better be a wise tradeoff.

Re:C meeting is over. C23 added: by WithinReason on Saturday February 19, 2022 @06:43AM (#30396369)
The downside of reordering being performance? Or something else?
Re:C meeting is over. C23 added: by 10x-dev on Saturday February 19, 2022 @07:05AM (#30396491)
Performance is usually the upside. The downside is subtle bugs that can happen due to side effects of the statements being reordered between sequence points.
Re:C meeting is over. C23 added: by WithinReason on Saturday February 19, 2022 @07:14AM (#30396554)
AFAIK compilers don't reorder if it would change the result.
Re:C meeting is over. C23 added: by Thiez on Saturday February 19, 2022 @10:05AM (#30397631)
Compilers not allowed to violate the language spec when optimizing. But the spec may be fairly generous in its allowed interpretations, which may not match what a programmer may naively expect. C, with its many undefined behaviors and implementation defined behaviors, is especially dangerous.
Re:C meeting is over. C23 added: by raptorfactor on Saturday February 19, 2022 @05:38AM (#30396035)
Having never used such a language, I'm curious, what's the debugging experience like? Can I source level step the application in the original language or do I have to debug the generated C?
Re:C meeting is over. C23 added: by rightbyte on Saturday February 19, 2022 @07:40AM (#30396699)
You can put in line pragmas for e.g. gcc that will point you from "foo.gen.c" to "foo.fancylang". However it is not very useful unless the fancy language matches C's structs and native types and also does not mangle names.
Re:C meeting is over. C23 added: by TingPing on Saturday February 19, 2022 @11:21AM (#30398217)
It is always a pain to debug transpiled C IME.
Re:C meeting is over. C23 added: by rwmj on Saturday February 19, 2022 @05:39AM (#30396040)
One of the criteria is "excellent debugging support" which you don't get with transpiled languages, since you'll be buried in generated code when you open the debugger.
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @09:45AM (#30397471)
Languages like Eiffel prove this isn't the case, it is a matter of proper debug tooling.
Re:C meeting is over. C23 added: by zabzonk on Saturday February 19, 2022 @11:15AM (#30398170)
Of course, Eiffel is such a popular and widely used language, with a great toolset. /s
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @12:44PM (#30398885)
The amount of users doesn't change the fact of the tooling quality, but no wonder, UNIX folks tend to only take free beer, so what do they know about fine wine.
Re:C meeting is over. C23 added: by zabzonk on Saturday February 19, 2022 @01:02PM (#30399041)
I've read the Eiffel books, and tried to use the Eifell tools, on Windows - a horrid experience. I am not a "UNIX folk" and I can't imagine what comparing UNIX and Eifell has to do with anything. It is basically an unuseable programming language and toolset, promoted by an egomaniac with a grudge against C++.

If you disagree, please provide a link to something medium sized and useful written in Eifel.

Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @01:38PM (#30399332)
Useful to whom?

To you or the companies that keep Eiffel Software in business for 30 years?

Re:C meeting is over. C23 added: by zabzonk on Saturday February 19, 2022 @02:07PM (#30399589)
> the companies that keep Eiffel Software in business for 30 years?

Such as? If you can't provide links to people using Eiffel succefuly, then maybe there are none.

Re:C meeting is over. C23 added: by pjmlp on Sunday February 20, 2022 @04:20AM (#30404385)
I can provide them, but you apparently will ignore them anyway, because it is clear a company can exist for 30 years without money.

Here is one, just to keep you happy.

https://washingtontechnology.com/2003/06/tech-success-xontec...

Yes, the article is from 2003, then again you haven't asked for dates, but to make it easier on you, you can ask them how they feel about Eiffel in 2022.

https://www.xontech.md/en/

Re:C meeting is over. C23 added: by dig1 on Saturday February 19, 2022 @07:13AM (#30396546)
Depending on transpiler (compilers that will compile to C), you can get near representation in C (rarely) or something completely different (frequently). In Scheme/LISP world (where transpilers were popular for a while), even a simple expression like "(+ 1 1)" will rarely give you something like: "int a = 1 + 1;". I've seen these things would produce dozen of lines of various boxing/unboxing calls, type checks and GC protection marks. If the compiler is really aggressive, it will just put "2" as a constant.

I think that the only benefit of "compiling to C" was reusing existing compilers, not tooling around it. Also, debugging that code is a nightmare unless you are intimate with transpiler internals.

Re:C meeting is over. C23 added: by sys_64738 on Saturday February 19, 2022 @08:00AM (#30396836)
A compiler that translates to another language used to be called a translator.
Re:C meeting is over. C23 added: by zabzonk on Saturday February 19, 2022 @11:13AM (#30398155)
All compilers covert programs in one language (say C) into another, (say assembler or machine code), and they are called compilers. The whole transpiler thing is a bit bogus, but a C compiler has never IME been called a translator.
Re:C meeting is over. C23 added: by mprovost on Saturday February 19, 2022 @01:31PM (#30399281)
C certainly has been battle tested but I wouldn't say that it passed with flying colours. Every one of the examples that you cite has had bugs/crashes/vulnerabilities that would have been avoided with newer languages.
Re:C meeting is over. C23 added: by brian_cloutier on Saturday February 19, 2022 @03:47AM (#30395484)
At a previous employer of mine we would have happily switched to c23. Postgres is written in c and if you want to write an extension for Postgres you're going to have the easiest time if your extension is also written in c. However, there's no reason not to use the newest c version.

So, c is not just for legacy code.

Re:C meeting is over. C23 added: by rwmj on Saturday February 19, 2022 @04:24AM (#30395661)
Many things on a Linux system is written in C, and despite the noise on HN, developers who gets stuff done are constantly writing new code in C all the time.
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @04:29AM (#30395678)
Including plenty of new CVEs, we have to keep the security industry job market safe.
Re:C meeting is over. C23 added: by rwmj on Saturday February 19, 2022 @04:33AM (#30395697)
Sure, I'm certainly not arguing that C is a good language. In RHEL we turn all warnings on, compile everything with hardening flags, use valgrind during development, and feed everything through Coverity.
Re:C meeting is over. C23 added: by axiosgunnar on Saturday February 19, 2022 @05:55AM (#30396120)
> In RHEL we turn all warnings on, compile everything with hardening flags, use valgrind during development, and feed everything through Coverity.

Surely the compile time is not 100ms anymore then?

Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @04:40AM (#30395727)
The exception that confirms the rule.
Re:C meeting is over. C23 added: by rossy on Saturday February 19, 2022 @11:11AM (#30398134)
The exception? It's standard practice for distros to compile with hardening flags, and if RH submits the bugs they find with Coverity upstream, that protects the 1000s of C projects they package.
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @12:53PM (#30398971)
Re:C meeting is over. C23 added: by torstenvl on Saturday February 19, 2022 @04:21PM (#30400651)
Mozilla is not a Linux distro.

You have made dozens of negative (and sometimes rude) comments in this thread. I'm curious why you're spending so much time and energy being negative. If C isn't something you're interested in, why not just ignore it and move on?

Re:C meeting is over. C23 added: by tialaramex on Saturday February 19, 2022 @07:21PM (#30401902)
> Mozilla is not a Linux distro.

That's true. But should I interpret this to mean, "All that stuff about how careful we are doesn't actually apply to any third party software, we only do that for code we wrote" ? Because the thing about a Linux distro is that it's overwhelmingly third party software.

If that stuff does apply to NSS, then all that hard work apparently missed this pretty serious bug that could not have happened in a safe language.

Re:C meeting is over. C23 added: by pjmlp on Sunday February 20, 2022 @04:30AM (#30404437)
C powers lots of junk where I as a user don't have a choice other than put up with security mitigations.

Being rude, yeah that is how people defend themselves when reality doesn't check.

Re:C meeting is over. C23 added: by diegocg on Saturday February 19, 2022 @05:36AM (#30396019)
> developers who gets stuff done are constantly writing new code in C all the time.

The amount of new C projects being created is falling at a fast rate. C isn't going anywhere, but it's certainly losing rapidly its prominence in the systems programming area.

Re:C meeting is over. C23 added: by rwmj on Saturday February 19, 2022 @05:42AM (#30396053)
[citation needed]
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @09:52AM (#30397518)
You can start by C compilers nowadays written in C++, Arduino, AUTOSAR security standard, CUDA, DirectX, Metal, GoDot, Vulkan helper libs, SYSCL, ...
Re:C meeting is over. C23 added: by phendrenad2 on Saturday February 19, 2022 @05:37PM (#30401196)
Those are just headlines, is there any evidence that those are actually overtaking C, and that the C++ used isn't just "C style C++"?
Re:C meeting is over. C23 added: by pjmlp on Sunday February 20, 2022 @04:09AM (#30404349)
Doesn't matter, if the code doesn't compile on a C compiler, it is C++.
Re:C meeting is over. C23 added: by sgt on Saturday February 19, 2022 @04:21AM (#30395646)
Sounds like you're not really in touch with the real word. C has many benefits and it is super practical. Yes, you can write unsafe code, but safety isn't always your #1 priority. There are also tools you can use to identify issues, which will mitigate risks.
Re:C meeting is over. C23 added: by KnobbleMcKnees on Saturday February 19, 2022 @06:23AM (#30396267)
I'm really starting to believe that there's a cohort of modern programmers that only see programming languages in terms of the high level syntactical features they provide.

The logic of it is something like: I write the code, I run a command written using similar code, scenes deleted, my program runs and my IDE tells me if there are problems in my code.

This is sometimes defined as the difference between developers and engineers, but I don't really buy the analogy because they're mostly highly competent and able to build solid and principled architecture into their software.

This is the only reason I can summise that educated programmers would say something like C is irrelevant.

I guess not everyone needs to have a depth of understanding of the platforms that underly their languages of choice, but - as demonstrated here - it certainly doesn't inform the future of languages when they are inherently tied to their ability to integrate with different hardware and OSs.

Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @09:48AM (#30397495)
It was already irrelevant when using MS-DOS with Turbo Pascal/Modula-2/Basic compilers, or Mac OS (originally written in Object Pascal/Assembly).

It was UNIX industry adoption, followed by GNU Manifesto that made to more relevant than it should ever have been.

Re:C meeting is over. C23 added: by rixed on Sunday February 20, 2022 @12:56AM (#30403568)
So, it's not relevant, but then it's more relevant?

Well, sure, merit and popularity rarely align, and one with enough technical culture can always imagine a better world.

Re:C meeting is over. C23 added: by Koshkin on Saturday February 19, 2022 @01:02PM (#30399044)
The truth is, C is merely a historical artifact, one step above the PDP-11 assembly, created in order to make the UNIX source code portable. It has transcended its original purpose, and with it being elegant and simple as it is, I would still never trust it to run a pacemaker.
Re:C meeting is over. C23 added: by jonp888 on Saturday February 19, 2022 @03:11AM (#30395303)
There are many many people out there using C for embedded software.
Re:C meeting is over. C23 added: by sam_bristow on Saturday February 19, 2022 @03:22AM (#30395357)
The problem is that embedded compilers are not known for keeping up with the standards. The only hope is that the moves to GCC and Clang continue.
Re:C meeting is over. C23 added: by bsder on Saturday February 19, 2022 @03:41AM (#30395463)
gcc (thankfully) is the default (you download gcc compiled for ARM directly from ARM itself) for ARM embedded so when gcc gets it, ARM gets it.

So, presumably, RISC-V will also get it at the same time.

Re:C meeting is over. C23 added: by pkrumins on Saturday February 19, 2022 @03:28AM (#30395383)
No one cares about the standards. We only care about getting things done by writing regular C code that works.
Re:C meeting is over. C23 added: by uncomputation on Saturday February 19, 2022 @04:53AM (#30395793)
Huh? What do you think defines “regular C code that works”? Standards.

Every compiler you have used operates at a bare minimum on the C standard. That’s why they are often advertised (if not GCC/Clang which are assumed to be up to date) as “C(89|99|11|17) compliant.” “Code that works” is code which is operates under constraints and guarantees specified by a standard, anything else is undefined or unportable.

Re:C meeting is over. C23 added: by xigoi on Saturday February 19, 2022 @01:27PM (#30399244)
I'll rather have code that runs on an actual computer than code that should hypothetically run according to a long document that costs 60 dollars to read.
Re:C meeting is over. C23 added: by pkrumins on Sunday February 20, 2022 @07:04AM (#30405071)
Exactly. You get it 100%. We should work together.
Re:C meeting is over. C23 added: by flyinglizard on Saturday February 19, 2022 @05:50AM (#30396094)
Embedded environments are specific and esoteric enough that compiler portability is the least of your concern when migrating code from one platform to the other.
Re:C meeting is over. C23 added: by pkrumins on Saturday February 19, 2022 @07:06AM (#30396499)
Only the standards people care about standards. We (programmers) want to just get things done. We don't care about the standards. No one reads the standards. Also no one cares about portability. All computers have been the same for the last 20 years.
Re:C meeting is over. C23 added: by drran on Saturday February 19, 2022 @07:23AM (#30396601)
We, developers, care about standards, because we want to get things done once.
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @09:56AM (#30397543)
Right, then comes the day another OS or CPU needs to be supported and some clever developers learn their lesson about language standards during a couple of late nights tracking down production issues.
Re:C meeting is over. C23 added: by vntok on Sunday February 20, 2022 @03:08AM (#30404124)
Seems way more efficient to not care about standards and invest a couple late nights once every five years.
Re:C meeting is over. C23 added: by pkrumins on Sunday February 20, 2022 @07:07AM (#30405087)
Exactly. You are the real MVP in this thread. We should team up.
Re:C meeting is over. C23 added: by mkl95 on Saturday February 19, 2022 @04:04AM (#30395568)
There are tons of CPython users AKA Python's default implementation... the software world is full of high level abstractions built on top of C.
Re:C meeting is over. C23 added: by kstenerud on Saturday February 19, 2022 @04:10AM (#30395599)
I will.

C is everywhere and is not going away (it's #2 on TIOBE and on the rise again). Now that fewer people are learning it, I get more juicy contracts.

Re:C meeting is over. C23 added: by reassembled on Saturday February 19, 2022 @04:26AM (#30395665)
I feel like there’s actually a growing subculture of C programmers of late, seemingly spawned by Casey Muratori’s Handmade Hero series, Zed Shaw’s “Learn C The Hard” way and other more recent popularizations of C and low level programming ideas. There’s a whole “Handmade” software scene growing up, seemingly as a reaction against the bloat and over engineering of more recent software trends like Electron and web apps. Just the other day I stumbled across a vibrant Discord group focused on a fairly new but surprisingly feature complete game engine called Gunslinger, written entirely in C99. I’ve been working on my own C-based game engine for awhile too after having been exposed to the ideas of Handmade Hero, as well as from the influence of a good friend who has been writing games in C for many years. He’s now working on an application called Pixel CNC for generating 3D tool paths from 2D images.
Re:C meeting is over. C23 added: by plafl on Saturday February 19, 2022 @05:00AM (#30395834)
C++ requires to devote your life to it but you can learn C and spend a year using it and suddenly you have a dangerous but powerful tool in your toolbox forever.
Re:C meeting is over. C23 added: by gefhfffh on Saturday February 19, 2022 @05:41AM (#30396045)
It's not like C++ is always the only alternative, see e.g. Rust which is way simpler
Re:C meeting is over. C23 added: by lumb63 on Saturday February 19, 2022 @08:38AM (#30397045)
I agree that Rust is simpler than C++ (in some ways), but I’d say it is far more complex than C.
Re:C meeting is over. C23 added: by Thiez on Saturday February 19, 2022 @10:11AM (#30397674)
That depends on how you define complexity. It is far easier to write a working program without memory leaks, various types of vulnerabilities, and undefined behavior in Rust than it is in C.
Re:C meeting is over. C23 added: by phendrenad2 on Saturday February 19, 2022 @05:54PM (#30401298)
It depends on what level of security you need. If you're writing a 3D game engine, a minor memory leak probably isn't worth the extra time required to write it in Rust. Even if you're writing a kernel, fuzzing and formal verification can get you 99.999 of the way to the guarantees of Rust.
Re:C meeting is over. C23 added: by Thiez on Saturday February 19, 2022 @06:48PM (#30401684)
I feel like writing Rust is a whole lot faster and less error-prone than writing something in C. But even assuming that it's slower, it's definitely much faster than writing C and doing formal verification. Naturally formal verification can help with other properties besides memory safety, and as far as I am aware Rust is still lacking a formal semantics so when you go all-in on formal methods C can reach a provable level of quality that Rust currently cannot. But very few people develop software that way.
Re:C meeting is over. C23 added: by saagarjha on Saturday February 19, 2022 @04:53AM (#30395792)
> seemingly spawned by Casey Muratori’s Handmade Hero series, Zed Shaw’s “Learn C The Hard” way

It's kind of unfortunately, really, because both authors have very skewed viewpoints of C that are arguably quite incorrect.

Re:C meeting is over. C23 added: by edflsafoiewq on Saturday February 19, 2022 @09:55AM (#30397541)
What viewpoints are those, for those of us unfamiliar?
Re:C meeting is over. C23 added: by saagarjha on Saturday February 19, 2022 @10:08AM (#30397652)
Zed Shaw doesn't really like C because it lets you shoot yourself in the foot. This is an OK opinion to have, but then he goes and writes books about C that basically talk about how the language is bad (ok, I guess?) but the then claims he has solutions to these problems, without understanding that the problems he has with C are not solvable within the language (for example, when handed an arbitrary pointer, there is no way to tell whether it is valid).

Casey Muratori is fundamentally at odds with how undefined behavior works in C and has opinions™ on how to fix the language to make things work the way he wants them to, when in reality he just probably wants another language.

Re:C meeting is over. C23 added: by Didah on Saturday February 19, 2022 @06:01AM (#30396155)
Out of curiosity: why do you consider Casey's viewpoint incorrect?
Re:C meeting is over. C23 added: by saagarjha on Saturday February 19, 2022 @09:59AM (#30397576)
Casey doesn't really understand how optimizing compilers work, so he likes to talk about how they keep breaking his code and that they should just run the optimizations that won't do that.
Re:C meeting is over. C23 added: by throwaway2214 on Saturday February 19, 2022 @05:37AM (#30396026)
also arguably quite correct
Re:C meeting is over. C23 added: by pornel on Saturday February 19, 2022 @06:40AM (#30396355)
C is probably still popular, but TIOBE is less accurate than a horoscope.

TIOBE index shows C has lost 62% of its users in 2016-2018, then almost tripled in popularity next year, and then again lost almost half of its users.

Do you think such swing of popularity is possible for such an established slow-moving language? I don't think so — it just shows how far TIOBE can diverge from reality, and that the error bars on the index should be +/- 50%. A few % blip means nothing. TIOBE is measuring rollouts of new Google search algorithms, not language popularity.

Re:C meeting is over. C23 added: by DyslexicAtheist on Saturday February 19, 2022 @04:46AM (#30395751)
> So who will use C23

I can't say if I'd immediately jump to C23 but I'll be thrilled to give it a try.

Currently I'm rewriting an entire automotive OCPP charging point and it's associated CSMS in C because the original dev (who has no experience with Edge/IoT and just Cloud/SaaS) thought it was a great idea to implement this in golang. The binary size alone is already a problem where all I have is 30MB (needs to be shared with logs, sqlite, and 2 another "user-space" application).

I could have chosen Rust/Zig/Nim (I really wanted to) but the client rejected it for very good reasons that have nothing to do with type-safety/performance/security but are all about good-business practice and risk management:

- when I leave in a few weeks, there are plenty engineers inside the company who can maintain the system.

- the domain is quite niche so to understand their solutions and requirements you can't do away without an occasional trip to their office. the client is not in a capital city with a vibrant tech-scene and weekly meet-ups and lacks the talent-pool.

The constraints by the market (scarcity) makes Rust/Nim/Zig (my personal front-runners) very risky tools.

C++ could have been an option but it's total overkill because most of the components you need to build this (websocket, mqtt, http, sqlite, zlib, openssl, ...) are anyway implemented in C and I actually don't want things like exceptions or templates in this _at all_ for performance reasons.

If you split your OS into layers from HW (ring-0) all the way to layer-5 (process management e.g. systemd etc) then 99% is still written in C. So your argument throws every layer under the bus except user-land (L-6).

C isn't going away only because of embedded/IoT. It's going to stay because choosing a language is like the "3 most important rules in real-estate: location. location. location".

The language is your location and your primary lock-in factor for your solution/business. Once you've decided on language the only way to change this is an entire re-write. Even if you rewrite you still have to consider culture and available resources that must be in place long before you chose the programming language. And keep in mind the people who all took stakes in the original implementation and must all be sold on the idea that whatever new replaces the old "is sooo much better". That's not an engineering problem but a power/people problem.

Edit: So just because "the engineer inside of me" wants to use Rust/Nim/Zig or whatever new to satisfy my intellectual curiosity is not enough reason. In fact my potential inability to see beyond that is a good reason for them to be very very careful about what advise I give.

Re:C meeting is over. C23 added: by WithinReason on Saturday February 19, 2022 @05:16AM (#30395917)
Is it a good summary that the only reason for deciding for C instead of Rust/Nim/Zig is that not enough programmers know Rust/Nim/Zig?
Re:C meeting is over. C23 added: by blinzy on Saturday February 19, 2022 @09:28AM (#30397364)
From my personal experience, at work we use C and not Rust because for really low-level code (e.g., kernel bypass, niche datastructures, real-time, etc.) I believe Rust would have to use "unsafe" due to work with raw pointers and other code that can't be easily, or at all, expressed otherwise. In such a scenario a lot of the advantages Rust supposedly brings are diminished or gone.

When that happens, considering that our company's knowledge/experience with C (or C++, although not my case) is vastly deeper than with Rust it makes no sense to choose it for any of that type of code we write, old or new.

Zig looks promising but it's still too soon to take any risk in adopting it; in 5 years time it may be worth revisiting it and see how it has matured...

Finally, software we may write but that gives us no competitive advantage over other businesses, sure that can be in Rust, Go, Java, Python, whatever.

Re:C meeting is over. C23 added: by DyslexicAtheist on Saturday February 19, 2022 @06:37AM (#30396331)
imo not the only reason but it's the most cited one by those who give me a budget and limit my freedom to use the tool I personally think is right for the job. just because I can sell an engineering audience on my (IMHO correct but artisanal) views doesn't mean it's what is best for the business.

Because they know the moment they come back "crying" saying "we can't find anyone with these skills" I'll consider it as their problem, because I for sure am not going to help sifting through LinkedIn profiles or get involved with their "talent acquisition strategy" (at least not in the capacity of an architect/engineer)

I'm not saying always use C but if you have a very narrow skill-set in your team then switching languages is a long-term strategic decision that goes well beyond the opinion of the SW-teams. It's about strategy, budget, risk. That's probably true for most new languages / tools that replace the status-quo and not just about C vs Rust&Co. If I bring in a new technology then I'd first use them in parts of the system that aren't core-business (e.g. my infra automation etc) and then gain experience slowly with them before considering allowing them into parts that make up my core-business. It's a long term project to adapt a new technology not something a few devs decide. (start-ups switching from MVP to real products might be an exception, as are bigger companies switching from PoC to a real implementation, etc.)

Re:C meeting is over. C23 added: by WithinReason on Saturday February 19, 2022 @06:45AM (#30396375)
Well then "legacy reasons" cited by GGGP was actually right. That's what I was wondering as well.
Re:C meeting is over. C23 added: by pkrumins on Saturday February 19, 2022 @03:26AM (#30395377)
We all use C because it works and we love to get things done.
Re:C meeting is over. C23 added: by drran on Saturday February 19, 2022 @07:21AM (#30396594)
Not all of us use C, because it's very easy to create security holes in C. For example, web browsers are using slow JavaScript just because it memory safe.
Re:C meeting is over. C23 added: by aardvark179 on Saturday February 19, 2022 @04:13AM (#30395611)
Huge amounts of software are “legacy” but built with perfectly modern tool chains and will support c23 just fine. Even for large bits of software which have been mostly rewritten you’ll often find core libraries that are still actively developed but have never been ported away from C.
Re:C meeting is over. C23 added: by foxfluff on Saturday February 19, 2022 @07:52AM (#30396783)
I will continue to use C because I haven't seen an appealing alternative.
Re:C meeting is over. C23 added: by phendrenad2 on Saturday February 19, 2022 @05:55PM (#30401310)
I'll keep writing things in C, because it maximizes my productivity and gives me extra time to make it secure (less time than it would require to write it in Rust in the first place).
Re:C meeting is over. C23 added: by shakna on Saturday February 19, 2022 @04:54AM (#30395806)
How many of your preferred programming languages are written in C?

Yes, many self-host, but a considerable number of them don't want the complications that can bring.

Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @10:01AM (#30397593)
Modern C compilers are written in C++.

So much for C's simplicity in writing compilers.

Re:C meeting is over. C23 added: by shakna on Saturday February 19, 2022 @12:02PM (#30398546)
Yes, C can be simple for writing a compiler. [0][1]

No, optimisation, on the other hand, is not a simple problem.

[0] https://github.com/rui314/8cc

[1] https://github.com/rui314/chibicc

Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @12:40PM (#30398853)
Naturally it can be simple, it was already a basic language when compared with what 1960's have produced.

The evolution of Bootstrapping CPL compiler + a set of basic types.

Re:C meeting is over. C23 added: by uecker on Saturday February 19, 2022 @01:17PM (#30399173)
There are plenty of C compilers written in C. Large compiler suites for C/C++ are usually written in C++. But as a contributor to GCC, I can say that large parts of the code still look very much like C.
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @01:36PM (#30399322)
Plenty of compilers... right.

If you cannot compile GCC with a C compiler, it isn't C.

Re:C meeting is over. C23 added: by uecker on Saturday February 19, 2022 @02:25PM (#30399726)
There a couple of open source C compilers TCC, SDCC, tendra, chibicc, ACK, LCC, PCC, etc. and also many commercial ones.

It is true that GCC is not written in C anymore, but it is easy to see that the code is still relatively close. I am also myself writing a C compiler in C at the moment and there is no problem at all.

Re:C meeting is over. C23 added: by pjmlp on Sunday February 20, 2022 @04:08AM (#30404339)
How many of those are actually shipping software into production?

Quite curious about which commercial C compilers, written in C, are being sold, keeping those companies in business.

Every year thousands of CS students write toy C compilers.

Re:C meeting is over. C23 added: by jstimpfle on Sunday February 20, 2022 @11:25AM (#30406866)
It will be hard to agree with you what "production" even means. I have written and shipped at least one compiler/interpreter (written in plain C). The language wasn't an issue at all. (This compiler doesn't have any meaningful optimizations, but I don't see why that should change the game).

GCC and Clang aren't "sold" either, nor is MSVC really.

I have never contributed to GCC, but as a fact I have visited plenty of files from its source code, and so far haven't encountered any meaningful use of C++ that couldn't easily be rewritten in plain C. The overwhelming majority of the code would probably compile as C without changes.

I'm sure that there are far more meaningful "problems" with the architecture of a compiler written in C that are not the implementation language. For example, GCC is a pain to build (IIRC when I tried many years ago, I gave up).

Re:C meeting is over. C23 added: by jstimpfle on Saturday February 19, 2022 @07:31PM (#30401961)
Trying to win a pointless argument based on pedantic logic that misses the point.
Re:C meeting is over. C23 added: by pjmlp on Sunday February 20, 2022 @04:05AM (#30404333)
Usually the typical answer when facts aren't appealing, the other way around apparently being pedantic matters.
Re:C meeting is over. C23 added: by jstimpfle on Sunday February 20, 2022 @11:11AM (#30406754)
Obviously one should always argue to the point instead of picking an interpretation that is easy to refute using "logic".
Re:C meeting is over. C23 added: by dkjaudyeqooe on Saturday February 19, 2022 @03:39AM (#30395450)
C is a portable alternative to assembly language.
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @04:29AM (#30395681)
When the world is a PDP-11.
Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @05:22AM (#30395959)
And x86, Arm, PIC, Xtensa,... and everything else.
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @06:12AM (#30396215)
There is where you went off rails, with greetings from ACM.

https://queue.acm.org/detail.cfm?id=3212479

Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @07:23AM (#30396599)
I'm so glad that you have linked this article from Chisnall. I can now ask you in what ways is the abstract model of a machine on which assembly language operates on, different from the one on which the C language operates on?

This is the claim which started this thread:

>>C is a portable alternative to assembly language.

Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @08:45AM (#30397083)
C's abstract machine is leaky and full of surprises when UB comes into play for one.

Second when people talk about C being portable Assembly, they mistakenly assume to know what comes out of the compiler's backend.

Third, unless we are speaking about PDP-11 like CPUs, modern CPUs have tons of capabilities not exposed to ISO C.

Finally, since 1958 there are portable alternatives to Assembly in systems programming with JOVIAL being one of the first remarkable ones, yet another thing that C did not invent.

Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @09:15AM (#30397263)
You haven't answered the question?

Maybe because is there is no concernable difference between abstract machine models of both languages? You can't do anything more about instruction reordering or cache invalidation at the CPU level with assembly than you can with C.

Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @09:59AM (#30397570)
You surely can, better read those CPU manuals about line bus controllers.
Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @10:23AM (#30397764)
Have you? I used to write device drivers mostly on ARM architectures and I have newer seen an instruction which would let me precisely control CPU instruction ordering or what it does with cache that I couldn't do in C.
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @12:51PM (#30398959)
That is why stuff like V-Tune exist with micro-ops profiler and pipeline debugging, maybe ARM should provide better tooling.
Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @01:30PM (#30399279)
This tool helps as much with C (or even higher level languages) as it does with Assembly. It doesn't change the fact both languages work on the same abstract machine model.
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @01:51PM (#30399444)
What is C's abstract model for NEON?
Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @02:24PM (#30399713)
A simple c library:

https://github.com/projectNe10/Ne10

You have not yet shown an argument for why c is not a portable assembly.

Re:C meeting is over. C23 added: by potiuper on Sunday February 20, 2022 @01:39AM (#30403730)
Access to CPU-specific flags like the carry flag. When doing a multiple-precision addition, if the CPU carry bit is inaccessible, then it must instead be compared to the result to see if it overflowed, which takes 3-5 more instructions per limb or worse on modern superscalar processors that are serial in terms of data accesses.
Re:C meeting is over. C23 added: by nec4b on Sunday February 20, 2022 @03:59AM (#30404305)
Portable by definition means it cannot capture every specific detail of every architecture out there.
Re:C meeting is over. C23 added: by potiuper on Sunday February 20, 2022 @09:52AM (#30406136)
The carry flag is not a specific architectural detail; it is part of the output from the prime example of a basic electronic circuit that is the digital adder.
Re:C meeting is over. C23 added: by nec4b on Sunday February 20, 2022 @07:10PM (#30410514)
It is an architectural detail. MIPS for example doesn't have a carry flag. You have to do the exact same procedure in assembly on MIPS you have described in your previous comment when doing multiple word addition.
Re:C meeting is over. C23 added: by potiuper on Sunday February 20, 2022 @08:38PM (#30411029)
MIPS along with DEC alpha do not have adder circuits as a design goal was not to have flags. This along with the scenario of multi-precision arithmetic resulted in the implementation of multi-precision arithmetic on MIPS and DEC alpha using a form of branch like instruction with an ALU stage instead of the unavailable instructions dependent on the alternative adder circuits. The choice of having or not having a carry flag alone is not an architectural detail as the choices of [micro]architecture involve how operations are implemented in circuits/hardware. The carry flag specifically has to be considered in the context of its [the adder] circuit when making architecture decisions. The lack of control over flags leading to the inability to compile the same C program to the same assembly operations with same behavior on different hardware demonstrates that a strictly C program is unable to express a consistent portable assembly program across all hardware.
Re:C meeting is over. C23 added: by nec4b on Monday February 21, 2022 @05:08AM (#30413910)
You are basically arguing CF == !CF. On MIPS you literally have to compare your result with an operand in order to establish if there was an overflow. On Arm you just look at the status register.

When I was doing embedded development, I used C as portable assembly in practice and I know I wasn't the only one. Can you do everything an architecture enables you in a portable way? No, of course not.

Re:C meeting is over. C23 added: by pjmlp on Sunday February 20, 2022 @04:29AM (#30404431)
By definition there isn't such thing as portable Assembly.
Re:C meeting is over. C23 added: by potiuper on Sunday February 20, 2022 @11:43AM (#30407006)
Not by definition, but by practice as generating assembly is usually done to optimize performance. Languages restricted to generate a common feature set between isomorphic ISAs and bijectively associated assembly languages are at a performance disadvantage compared to the full ISA specific assembly.
Re:C meeting is over. C23 added: by pornel on Saturday February 19, 2022 @06:47AM (#30396387)
Where's my overflow flag?
Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @07:27AM (#30396621)
Not all CPU's have overflow flags. On those that have them, you can also usually access them in C in a non portable way.
Re:C meeting is over. C23 added: by uecker on Saturday February 19, 2022 @01:21PM (#30399205)
C23 will get support for checked integer operations that report overflow.
Re:C meeting is over. C23 added: by kaba0 on Saturday February 19, 2022 @06:11AM (#30396202)
I don’t see my SIMD instructions anywhere.
Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @07:16AM (#30396561)
The word "portable" means a subset of everything possible. Do you think every CPU architecture supports SIMD?
Re:C meeting is over. C23 added: by foxfluff on Saturday February 19, 2022 @07:51AM (#30396773)
> The word "portable" means a subset of everything possible.

Exactly; for example, C has single precision and double double precision floating point, 64 bit types, and complex arithmetic because every CPU architecture has those built-in.

Re:C meeting is over. C23 added: by nec4b on Saturday February 19, 2022 @08:38AM (#30397044)
No, but those things can be easily emulated on every hardware or simply not used. One more reason to use C instead of plain assembly.
Re:C meeting is over. C23 added: by jdkjs on Saturday February 19, 2022 @06:54AM (#30396428)
Re:C meeting is over. C23 added: by pjmlp on Saturday February 19, 2022 @10:00AM (#30397583)
That isn't C, rather Intel C.