Hacker News

Top stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. Korea raises data breach fines to 10% of revenue(koreajoongangdaily.com ↗)
    20comments
  2. Android 17 is the first since 3.x to add new APIs without releasing to the AOSP(grapheneos.social ↗)
    95comments
  3. Saving another 100TB of RAM with math (and Rust)(cloudflare.com ↗)
    12comments
  4. Cloudflare Quick Tunnels(cloudflare.com ↗)
    192comments
  5. Apple releases iPhone Duo simulator and Xcode 27.1 beta(developer.apple.com ↗)
    33comments
  6. Cache-to-Cache: Direct Semantic Communication Between Large Language Models(arxiv.org ↗)
    9comments
  7. Photon-Emission-Guided Laser Fault Injection Enables RP2350 Secure Debug(ledger.com ↗)
    35comments
  8. Show HN: Cactus Needle 3: 8-29MB automation models can match DeepSeek V4 Flash(cactuscompute.com ↗)
    59comments
  9. OpenJev(openjev.com ↗)
    233comments
  10. The Implications of Linguistic Illegibility for LLM Security(arxiv.org ↗)
    10comments
  11. C++26: Trivial infinite loops are no longer undefined behaviour(sandordargo.com ↗)
    141comments
  12. Border agents can search cellphones without a warrant or reasonable suspicion(lawandcrime.com ↗)
    72comments
  13. The first new cat species discovered in 100 years(nationalgeographic.com ↗)
    17comments
  14. Our brain evolved from two primitive nervous systems that merged: Study(newscientist.com ↗)
    37comments
  15. I vibed a proof of Conway's conjecture(overreacted.io ↗)
    165comments
  16. How SpaceX streamlined the Raptor engine(construction-physics.com ↗)
    13comments
  17. North Korean nuclear test sets off years of earthquakes(science.org ↗)
    135comments
  18. Minimal Phone 2(minimalcompany.com ↗)
    105comments
  19. Inside ZCode: Silently uploading your Git history to the cloud(ferstar.org ↗)
    84comments
  20. Show HN: Ax-check.com – Can agents use your product?(ax-check.com ↗)
    22comments
  21. Warez: The Infrastructure and Aesthetics of Piracy (2021)(archive.org ↗)
    8comments
  22. A search-and-inference database from scratch in pure Zig(antfly.io ↗)
    6comments
  23. US Military had close call after using AI for hallucinated intelligence report(cnn.com ↗)
    224comments
  24. Cekura (YC F24) Is Hiring(ycombinator.com ↗)
    discuss
  25. Show HN: Scry, programmable internet search w/ congestion pricing(scry.io ↗)
    15comments
  26. How to Write with an LLM(sockpuppet.org ↗)
    212comments
  27. "From Geometry to Algebra and Back Again: 4000 Years of Papers" (2023) [video](youtube.com ↗)
    discuss
  28. Jemalloc 5.4.0(github.com/jemalloc ↗)
    85comments
  29. Mathematicians Build Long-Awaited Graph Sandwich(quantamagazine.org ↗)
    16comments
  30. The scourge of x86 emulation(fex-emu.com ↗)
    73comments

Checked C

336 pointsby 10y agoresearch.microsoft.com
145 comments
10y agoHN ↗

It would be nice to merge these two submissions' comments.

10y agoHN ↗

the obvious question: how does this compare to rust? it looks like rust and this aim to solve a very similar set of issues in more or less similar way ('static and dynamic checking'). i'd be very interested in a table that compares capabilities of both. of course there's a gigantic advantage of this being C, so in theory valid checked C would be valid C with all benefits of that.

10y agoHN ↗

Well, this isn't C: it's a different language that extends C. There's a big difference between that and just being C. In particular, valid checked C is not valid C, because checking requires using the language extensions.

Regarding the comparison to Rust, Rust prevents use-after-free, while this doesn't seem to from a skim of the paper. Use after free is one of the most, if not the most, common remote code execution security issues in C and C++ code nowadays.

10y agoHN ↗

Use after free is one of the most, if not the most, common remote code execution security issues in C and C++ code nowadays.

I'd love to see a citation on this. My gut feeling tells me buffer overruns and integer overflows are seriously in the running.

10y agoHN ↗

It is certainly "one of the most", even if it is not "the most".

10y agoHN ↗

I'd love to see a citation on this, as I asked for previously. Repeating the comment I replied to isn't a citation.

10y agoHN ↗

That is somewhere around asking for a citation if the sky is sometimes cloudy.

https://web.nvd.nist.gov/view/vuln/search-results?query=use-...

Before getting too excited and claiming that it's only 1.3% of all CVEs or something, remember that it's 1.3% of all vulnerabilities. (Especially with the explosion of dynamic web languages, a lot of CVEs aren't really C/C++-related.) There's a power law to these things, so by the power law metric, it's not that far behind "buffer overflow" (6,500 entries), and ahead of the well-known "format string" (577), which is also certainly "one of" the most common C issues.

10y agoHN ↗

I'm looking specifically for remote code execution vulnerabilities, which is what the original comment was discussing, and which is a subset of what you posted.

And no, this is not like asking for citations for the sky sometimes being cloudy because the original comment didn't say "use-after-free sometimes leads to remote code exploit".

This is like asking for citations for a claim like "whenever the skies are cloudy it is due to acid rain more than any other reason". And a claim like that should be accompanied with some citations.

Let's have an honest discussion here, or don't bother, please.

10y agoHN ↗

Every single Pwn2Own vulnerability this year was UAF.

10y agoHN ↗

I don't believe pwn2own is representative of the security landscape in general.

Is that the only information you based your comment on?

10y agoHN ↗

I don't believe pwn2own is representative of the security landscape in general.

It's representative of the state of the art in attacking large, mature, modern C++ codebases.

Is that the only information you based your comment on?

No, it's due to watching lots of security bugs go by over the last several years. I work in this space, you know.

10y agoHN ↗

It's representative of the state of the art in attacking large, mature, modern C++ codebases.

I would say it is representative of attacking client side desktop browser software and plugins. That seems quite a bit less representative of all C and C++ software, most notably excluding server-side software.

I work in this space, you know.

That's why I was hoping for something more than "trust me" as a citation.

10y agoHN ↗

Rust's safety comes at a cost as it is not as fast as plain C. If Checked C's checks are run at compile-time it would be as fast as C.

10y agoHN ↗

This seems to be a successor to CCured from 2005, a project partially funded by Microsoft. [1]

The general idea is straightforward: "The unchecked C pointer type * is kept and three new checked pointer types are added: one for pointers that are never used in pointer arithmetic and do not need bounds checking (ptr), one for array pointer types that are involved in pointer arithmetic and need bounds checking (array ptr), and one for pointer types that carry their bounds with them dynamically (span)." So this is really a new language derived from C, to which programs can be converted.

This is basically a good idea, but it's only useful if pushed hard by somebody like Microsoft. People won't convert without heavy pressure.

[1] https://www.cs.virginia.edu/~weimer/p/p477-necula.pdf

10y agoHN ↗

I thought so too, but looking at their paper, they have an impressive survey of prior approaches, and they explain their differences from CCured quite well. CCured used fat pointers, and apparently modified the data pointed to by WILD pointers (something I didn't know).

This seems interesting to me. I liked the way CCured did inference to document how you used and abused your pointers, but what it did with that information was maybe not ideal.

10y agoHN ↗

A link to the paper you are mentioning would be helpful.

10y agoHN ↗

Being pushed by Microsoft could be exactly the reason not to convert, for many people. Especially when there is no shortage of alternatives that are backed by a bit more benevolent entities (Rust, and many other less known variants).

10y agoHN ↗

To put things in perspective, consider than from web browsers and languages, to their respective ill-fated mobile OS efforts, nothing Mozilla created has ever gotten more adoption than something MS created.

10y agoHN ↗

Only if we don't count Netscape and JavaScript. They put it in the browser, for better or for worse.

10y agoHN ↗

Why would we count Netscape and Javascript?

We're talking about Mozilla.

Netscape was a different company -- and besides we're discussing under the context of MS vs benevolent/FOSS entities.

10y agoHN ↗

Just FYI, Statista is a private company. You may be thinking of http://destatis.de/, which is the homepage of the German federal office for statistics.

10y agoHN ↗

In reply to myself: The times are changing indeed. It seams that HN-ers started liking Microsoft. Whenever I post some concern, even if only mild, there is first a few upvotes, and then a bunch of downvotes.

Microsoft became the darling of the community, OR, in addition to embracing open source, they embraced voting ring tactics. These are two explanations I have, maybe there is another. Maybe my criticism really was obnoxious...

10y agoHN ↗

Maybe my criticism really was obnoxious...

Well, the "maybe in addition to embracing open source, they embraced voting ring tactics" part sure is.

10y agoHN ↗

Maybe it's just because yes, we all remember the 90s. But today is not necessarily the 90s. It was a lot more recent that Google was a relatively benevolent company, and we've all seen how that's changed.

And the thing about open source projects, is just that. They're open source. If the wider community takes hold of them, there's not much Microsoft can do. Because then you just see a fork.

You don't have to be a fan of Microsoft to simply appreciate the contribution to open software, as it is.

10y agoHN ↗

The only catch in that perspective is that the language specification is open source, while Microsoft's compiler implementation is not.

So, yes, we can edit those TeX documents they put on GitHub to our heart's delight.

10y agoHN ↗

pff.. they are "open source" just because they want to attract developers, because without developers writing apps for their platform, Microsoft will die (as any other platform). They are still just money-makers and nothing else, there is no any idea except money behind their movements to Open Source world, otherwise they wouldn't take revenues from Android.

10y agoHN ↗

Everything you say may (probably is) true.

Now why does anything in your post matter?

10y agoHN ↗

Because it's important to distinct intention to contribute to open-source world and intention to use this world to make money.

10y agoHN ↗

Because ocdtrekkie was using Microsoft's open source strategy to imply that Microsoft is no longer pursuing the same goals as before. EugeneOZ explained that Microsoft's strategy does not preclude their earlier goals.

10y agoHN ↗

last time I checked Microsoft was a company (not a platform) and like any other it has to make money to survive. Your saying is applicable to every other company releasing open source code

10y agoHN ↗

Approaches of Mozilla and Microsoft are quite different.

10y agoHN ↗

Did you think they would suddenly start waving "information wants to be free" flags?

10y agoHN ↗

You are dismissive of "attracting developers" as motive. That has always been a marketing ploy of the open source camp as an alternative to a fully open philosophy i.e. information wants to be free.

10y agoHN ↗

Forced updates for Windows 10 burned all the credibility Microsoft was slowly regaining. Whatever might be going on in there, they still have enough of the old strongarm bullying monopolist in their collective corporate character that their good works really cannot be trusted over the long term.

10y agoHN ↗

What about forced updates makes them bullies? Or are you just generally angry?

10y agoHN ↗

I'm angry about the idea that forced updates might become a normal practice, because that could lead to a situation where it's difficult to find much software I am willing to use.

"Power to the people" has always been the whole point of personal computing, as far as I'm concerned. Give people control over their data, their processes, their lives; that's why we're doing this, isn't it?

That's why I'm doing it, at least.

10y agoHN ↗

Power to the user is one aspect of personal computing. But with the rise of mobile and now IoT, the user has also become (increasingly) a 'consumer', and thus the software and hardware are getting more and more locked down. Hardware and software manufacturers will sleep easier at night when their products cannot (or can only limitedly) be modified.

I think the writing is on the wall. Computing devices will split into two diverging branches: one tailored for limited configuration and aimed at media consumption and use by non-tech users, the other providing (hopefully) full freedom to modify, aimed at IT co. and interested hobbyists. It will be quite some achievement if mechanisms to increase vendor control aren't increasingly integrated even into the devices in the second segment, as things like Intel ME/UEFI Secure Boot show.

10y agoHN ↗

My Android has forced updates. I have to put my phone in airplane mode before each reboot and kill the process to prevent it. Chrome has forced updates. A lot of things have forced updates these days, and nobody bats an eye about it. Microsoft does it, everyone loses their minds.

And 'forced' is a stretch anyways, how to block it is well documented, and was months in advance. And you can revert, something Google and others will not let you do.

10y agoHN ↗

- Security update != version update.

- Paid OS != Free OS.

- OS update != software update.

10y agoHN ↗

I sure bat an eye about it. I won't use Chrome.

I also deleted all the Google apps I could find on my Android phone, and I avoid storing any of my personal data on it, because Google seems to believe it's their machine, not mine. I'd use some other mobile OS if I had any choice in the matter.

10y agoHN ↗

Microsoft was still under US Federal oversight as of 2010. Two years ago, Ballmer was still CEO. It takes a long time to turn a big ship.

10y agoHN ↗

It seams that HN-ers started liking Microsoft.

Or maybe we stopped categorically demonizing some technology because of its provenience and started evaluating it based on criteria like usefulness and applicability.

You know, like if we actually take the "engineer" part of "software engineer" seriously instead of using it for everyone who once wrote a PHP page for his uncle.

10y agoHN ↗

it's funny how you are demonizing PHP in your comment

10y agoHN ↗

He is "demonizing" some "typical PHP programmer". It's not the languages fault that it is allegedly often used by novices to start their first website project, and that by no fault of their own those novices do not have any appreciable CS education and thus build their programs like I build a sandcastle: keep trying random things until it does not fall over anymore.

The argument is exactly to make this difference. There is the technical and somewhat objective aspect of the language and its implementation, and there are the people who created the language, who use the language etc. A bad language can have a great community, and vise versa.

10y agoHN ↗

Right, but not because of who made it, but because of its merits. Which is how things should be demonized.

10y agoHN ↗

I don't think this project is an instance where this is an important aspect, but in general I do agree that some caution is warranted when using an open source project backed by a corporation (Microsoft or anyone else) in your code. As someone who was recently burned by what happened to RoboVM[1], I am now always careful to check for any CLAs that are required to contribute to open source projects before I decide to use them in anything important.

The fact than you can fork is nice, but if the project is too reliant on the paid staff and doesn't have enough community surrounding it to survive getting dropped by its benefactor, you better hope you have the resources to maintain it yourself. This can happen even with no ill-intention involved, but the whole RoboVM debacle has convinced me that Embrace, Extend, Extinguish is not quite dead at Microsoft.

[1]: https://news.ycombinator.com/item?id=11503808

10y agoHN ↗

How many startups have been killed by other corporations, including Google, FB and friends?

The RoboVM situation, while unfortunate is a lesson for people not to rely on proprietary tooling for portable projects.

While I mostly code on JVM and .NET languages during the day, I use C++ for my hobby projects on mobile OSes.

The reason being that C++ is an open standard and officially supported in all SDKs, no need for third party layers like RoboVM.

A few similar lessons with my time spent on programming languages that weren't first party on platform SDKs, made me always choose first party languages, if I have decision power in the selection process.

10y agoHN ↗

How many startups have been killed by other corporations, including Google, FB and friends?

Yeah, that's why I said "Microsoft or anyone else". The only other time I mentioned Microsoft was in reference to RoboVM, which doesn't have much to do with Google or Facebook.

The RoboVM situation, while unfortunate is a lesson for people not to rely on proprietary tooling for portable projects.

I agree, but the fact that RoboVM started off open source with a GPL licensed compiler was one of the main reasons I chose it. It's my own fault I didn't look to see how contributions were structured, or notice that very little code came from outside RoboVM, sure. That's why I'm advising caution in similar situations.

10y agoHN ↗

Where did Microsoft employ embrace or extend before extinguishing RoboVM? They bough Xamarin for Xamarin, and ended up with a RoboVM they didn't want. There was no RoboVM strategy there.

10y agoHN ↗

If that's all, it's nothing that cannot be done in-language with smart pointer/iterator types in C++.

10y agoHN ↗

but I don't want to move my embedded C projects to C++. If I can use a language extension to get some extra confidence in my programs without changing the language im using then that's a compelling proposition.

10y agoHN ↗

but here in the case of Microsoft Checked C , you still need to modify your actual source code to get safer one.

10y agoHN ↗

But you're moving to a safer subset, not a safer superset, so it still shouldn't require significant alterations.

10y agoHN ↗

Uhhh moving from set to subset is what requires alterations, set to superset does not, by definition.

The problem here is compiler support and performance.

10y agoHN ↗

C++ is an altered and extended form of C, thus I would say it is more accurate to call it a superset, rather than a subset. I'm not using precise definitions here.

And of course, but those will come in time. The point of it is that C++ isn't any safer (And actually, I would say is more risky in some aspects, because of the differences between (For example) the UB in C and C++), while Checked C is guaranteed to be safer, to a certain degree.

10y agoHN ↗

OK, I have to admit that Checked C is probably strictly safer while C++ is ... a mixed thing (both safer and more complicated).

10y agoHN ↗

The difference between a language extension, and a new language, is one of degree, not kind. Personally, since the semantics of this "extension" go to the core of what one does in C, I consider Checked C a new language.

10y agoHN ↗

I agree, in principle. But reading over this document, the changes can be made in an incremental fashion. And with far less impact than switching to using C++ just for these (assuming equivalents exist) features.

10y agoHN ↗

switching to c++ can also be done in an incremental fashion.

10y agoHN ↗

Yes, but not quite as trivially as:

  Enable extension
  Add `checked` to array declarations. (for the simplest
  case they've implemented).

Converting to C++ also means making sure you have `extern "C"` in your function declarations to get around C++'s name mangling when calling C libraries. Among other, potential, source level changes. Or, similarly, making sure your C (now C++) library can be called correctly by C projects that depended on it.

I'm not sold on this project as we haven't seen any results of course, but the approach is simpler than switching to C++.

10y agoHN ↗

There are also some nice C99 syntax features like compound literals that may not be supported by your C++ compiler.

10y agoHN ↗

since many C programs will have simple array types like that, this addition is mostly syntactic.

10y agoHN ↗

Indeed, checkedc also introduces these 3 new pointer types (ptr, array-ptr and span). It also introduces invariants on variables, arguments and return values:

Quoting from the paper (https://github.com/Microsoft/checkedc/releases/download/v0.5...):

Reasoning about the correctness of programs with declared bounds sometimes requires reasoning about simple aspects of program behavior. To support this, lightweight invariants are added to Checked C. A lightweight invariant declares a relation between a variable and a simple expression using a relational operator. An example would be the statement x < y + 5. Lightweight invariants can be declared at variable declarations, at assignment statements, for parameters, and for return values. Checked C is extended with rules for checking these lightweight invariants. Just as type checking rules are defined by the programming language, so are rules for checking lightweight invariants. The checking of the correctness of programmer-declared bounds is integrated with the checking of invariants.

10y agoHN ↗

It is a design goal to allow Checked C to be a subset of C++ too.

Interesting. In times when many people advocate a safe C++ subset, Checked C grows the other way, adding C++-compatible notation to represent the most vital things like smart pointers.

10y agoHN ↗

You should look at their paper. They have an impressive survey of prior approaches including Cyclone, and they claim that their approach (if I understand them correctly) could allow you to do some things outside of unsafe blocks if implemented in C# or Rust.

10y agoHN ↗

I don't see any use-after-free prevention here from a skim of the paper, so this doesn't seem to address many of the most important benefits you get from C# or Rust.

Use-after-free is not a theoretical problem. All of the Pwn2Own vulnerabilities this year were UAF, for example.

10y agoHN ↗

The idea is nice (although old and tried more than once), but I'm pessimistic as it doesn't seem to be backwards compatible and requires a specific, new compiler. For legacy projects it's hard/impossible to change a toolchain/compiler and for the new projects one can as well use Rust or other modern language.

10y agoHN ↗

Interesting. I thought Microsoft has stopped liking C a while back. Remember complaining about C99 support in VS and getting a response about "Just use C++ compiler as a C compiler, you don't need C anymore". It took them until VS 2015 finally to support it.

10y agoHN ↗

VS 2015 still doesn't fully support it as such.

People apparently aren't aware that C++14 requires C99 libraries, hence the update.

Even the new refactored C library was written in C++ with extern "C" for its entry points.

The official wording is that those that still care about C compatibility on Windows should make use of the new clang frontend + Visual C++ backend.

MSR and real Microsoft are different business units.

10y agoHN ↗

Also the DDK (Windows Driver Development Kit) didn't support C++ in any meaningful way. If I remember correctly, all my drivers had to be written in C89.

10y agoHN ↗

C++ is supported in kernel space since Windows 8.

10y agoHN ↗

VS2015 only got support for C99 because of the C++14 requirements.

10y agoHN ↗

Good timing for me, since I have been falling back to C for some personal projects. I keep looking at Rust, but I just don't have the time. It would be nice to leverage the experience I already have, and see what Checked C offers.

10y agoHN ↗

This clarifies the need for a more "rust-like" C. I hope something like this will flow into standard C...

10y agoHN ↗

I wouldn't bet on it. Every safety feature added to the standard since C99 has been quietly dropped by compiler maintainers.

People could write safe code in the 70's. The point of C was to write high level (kinda portable) assembly. Not safety.

10y agoHN ↗

Every safety feature added to the standard since C99 has been quietly dropped by compiler maintainers.

Can you give one example of this, please?

10y agoHN ↗

Bounds checking interfaces in C99

Support:

GCC: Nope, why? Performance concerns

MSVC: Nope, why? Performance concerns

Clang/LLVM: Nope, why? Performance concerns. [1]

[1] LLVM has the op-codes to implement this, but Clang won't emit those op-codes with the c99 switch triggered.

10y agoHN ↗

Bounds checking interfaces in C99

... are an optional part of C standard library. C11 Annex K.

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm

So just use a library for those and you get support in every compiler!

MSVC: Nope, why? Performance concerns

MSVC runtime library does support an early version of that. Has supported for over 10 years. They contributed it to the standard, I think.

Example, sprintf_s, present in MSVC2005: https://msdn.microsoft.com/en-us/library/ce3zzk1k(v=vs.80).a...

Anything else?

10y agoHN ↗

I can't upvote this enough. I started to play with Rust a few months ago and I especially like their compile-time checks of the code. I don't see why C compiler vendors can't do the same thing. Imagine if folks like GreenHills or WindRiver adopt such a practice in their compiler. It would revolutionise their industry. IAR has MISRA-C checks in their compilers but that is not enough.

10y agoHN ↗

Because the C language is fundamentally hostile to Rust's safety features.

10y agoHN ↗

There's already an industry providing static analyzers for C (Coverity, Klocwork, Polyspace, etc). If you're doing mission-critical C you're probably using these already.

10y agoHN ↗

I do, but I wish it was built in, like rustc.

10y agoHN ↗

Microsoft style - be too closed to adopt existing solutions, always invent own ways/standards.

10y agoHN ↗

I've written lots of C and never had problems with buffer overruns, bounds checking, double frees, and other memory issues. Typically at a glance in one's code, I can tell when behavior may be undefined, and once someone has a little experience, they can avoid undefined behavior altogether. Why does so much work go into fixing these problems? In other words, what are some examples of use cases of a stricter language like this, that would be too complicated for human eyes to quickly verify?

10y agoHN ↗

A constant stream of memory-safety related vulnerabilities get found in popular C and C++ programs, many exploited in real attacks. If you haven't "had problems", then either you're far better than most experienced programmers, or you just haven't had many people examine your code with the explicit intent to cause problems. :)

10y agoHN ↗

Here you don't check the return value of calloc():

https://github.com/AndrewBelt/bored/blob/master/src/map.c#L3...

and then access it:

https://github.com/AndrewBelt/bored/blob/master/src/map.c#L4...

Here if realloc() fails, you'll have a memory leak and, again, accessing NULL later:

https://github.com/AndrewBelt/bored/blob/master/src/priq.c#L...

There is also integer overflow: alloc is int, so if it becomes greater than 2^31-1, it may wrap around [I think signed int behaviour in C is undefined in this case], and you'll allocate fewer bytes than needed, leading to buffer overflow.

10y agoHN ↗

Well, to be honest, very few programs are able to orchestrate >2GB allocations correctly when complied to 32 bit binary, like Visual Studio linker is not aware of >2GB sizes by default (one need to /LARGEADDRESSAWARE flag for it), which was a trouble for modern browsers because linker was unable to fit everything in limited virtual address space.

And another to be honest, very few programs on desktops/mobile are actually checking return values of malloc/calloc, because of amount of data that program operates is usually much smaller than amount of RAM available. It's sure a case for embedded, but you simply usually don't use malloc for embedded.

10y agoHN ↗

I've written lots of C and never had problems with buffer overruns

Well, if that is true, you are either very lucky or very brilliant. I have written moderate amounts of C, and I have run into those problems repeatedly.

Maybe that just means I am an idiot, but it appears that smarter people than me make such mistakes as well (although less frequently, I hope). C - at least when compared to most other popular languages - makes it very easy to make such mistakes.

Why does so much work go into fixing these problems?

Because these problems have cost lots and lots of money thanks to crashing or misbehaving software (including many a security problem). Not to mention the sanity of the programmers who had to debug these...

(Also, I am told that in embedded/realtime software memory management is a lot simpler, as malloc/free are typically not used; you didn't say what kind of C code you have written, but if you are an embedded developer, that would at least partially explain your experience.)

10y agoHN ↗

I've written lots of C and never had problems with buffer overruns, bounds checking, double frees, and other memory issues. Typically at a glance in one's code, I can tell when behavior may be undefined, and once someone has a little experience, they can avoid undefined behavior altogether. Why does so much work go into fixing these problems? In other words, what are some examples of use cases of a stricter language like this, that would be too complicated for human eyes to quickly verify?

Some memory issues with code you might be familiar with... From your own repo.

https://github.com/AndrewBelt/game_of_life/blob/master/src/g...

Not checking for return values is not a great idea. Your code blows up phenomenally with certain "width" and "height" values. It does check against negative grid sizes, but that's not enough (https://github.com/AndrewBelt/game_of_life/blob/master/src/g...)!

With suitable width & height it'd also gladly free a "grid" it never allocated. Of course it crashes long before that happens.

Ok, so it was cloned from someone else's repo, and you never got around cleaning it up.

Let's see...

https://github.com/AndrewBelt/bored/tree/master/src

Ok, still not checking return (SDL, etc.) values. Debug build asserts are better than nothing -- didn't bother to check how your build is configured.

10y agoHN ↗

This greatly lacks an overview as the specification[1] is very in-depth.

I kind of wonder if they're working on automatic conversion tools between C and checked C. At least for ptr<> this should be trivial. If a function does no pointer arithmetic with a * pointer and only uses it in function calls that take ptr<>, can be converted to a function taking a ptr<>.

[1] https://github.com/Microsoft/checkedc/releases/download/v0.5...

10y agoHN ↗

Amazed at the amount of open source coming out of MS these days, very nice !

10y agoHN ↗

So they couldn't be bothered to contribute that directly back to LLVM/Clang or am I missing something?

10y agoHN ↗

Baby steps.

The phrase "couldn't be bothered" is assuming a lot of bad faith on Microsoft's part. While I would agree that in times past MS didn't deserve the benefit of the doubt, these days they're a different company.

With no special insight into their reasoning, I think the more likely answer to the question, "Why didn't they contribute this upstream?" is probably "Give it time."

10y agoHN ↗

why? I mean if you think you really need checked C, then why not just use C++?

10y agoHN ↗

You know, some people seem to scoff at replacement Cs. I'm kind of one of them. I know my reason(s) though. It's not about other languages as much as C itself. I've been with it for awful long time now and I used to think I kind of know my way around it. I've changed that line of thinking, because I know it's not true. I make a lot of mistakes, especially considering memory. At least (almost all of) my code isn't public-facing.

Since I thought I knew C very well, I came to realisation (due to many memory bugs/leaks) that maybe that's not the case after all. What is it then? I can get performance out of it, lots of it (that's one thing I know to do, somewhat at least). That's when I questioned myself and started thinking that it's not that I know C (I don't, after 20 years or so), but that I am very comfortable with it and I don't want to change that comfort. C++ and 90's traumas and post 90's (STL) traumas had a lot to do with it. Now, I'm fishing out for newer languages that would replace C for me, Rust namely, but I'm still falling back to C all the time. Now, I'm thinking that that's just the way it is. I'm a C programmer and that's how it will stay. At least for a long while. I do and have used a lot (A LOT) of languages in my past, but my core is always C (also first language I've learned). I don't program anymore for a living (I do "creative stuff" in film and tv now), so that is now more prominent than any other time in the past. I do stuff for me only and I can pick and choose whatever I want to - yet, it's always C.

Sorry for the "rant".

10y agoHN ↗

All of the things which the C-like replacements for C are competely missing the point. All their goals can be achieved by using a decent high level language (not "C like"), together with using C for just those parts that have to run fast, or interact with the hardware.

"Let's make an improved C, and then write millions of codes in nothing but that" is a myopic non-starter.

10y agoHN ↗

How does this apply towards library creation, where the code is meant to be consumed by other programs languages?

While the total lines of code in libraries is less than that in applications, I would say the relative importance is more. That zlib has a fast and correct implementation matters to a lot of people.

10y agoHN ↗

That's right; one fast and correct zlib matters more than giving everyone an improved C so that they can all try to roll their own zlib that is fast and correct.

10y agoHN ↗

My comment was mean to point out that even if we magically achieved your dream tomorrow, and almost all applications were written in some HLL (which is probably a good thing), the amount of machine code being run in those applications that was generated from C is still substantial due to library use. If we accept that C is "bad", or at least that some major gains in usability, reasoning and security can be made by changing or replacing it, then there's still a major benefit to doing so.

When a bug comes out in zlib (or more likely, OpenSSL again), and we can attribute it to poor engineering in C, it doesn't really matter that all the applications are written in a HLL if they still loaded the library and used it because the performance was needed.

10y agoHN ↗

This mirrors my experience. C is a drug man. It's bad but you can't stop. You know how to get shit done in C and it's easy to think in. C is, IMO, something of a local optima for programming. Problem is, it's actually a relatively awful language, and I don't subscribe to the worse-is-better philosophy (though C may well be the best example of it).

Thankfully Rust gets my ML instincts going. I'm trying to use it more. It'll be nice not to be anxiously running my test suite under ASAN after every build.

10y agoHN ↗

Yeah but after sixty years of C, why should we trust an origanization like Mozilla? They've been thoroughly unwilling to come up with any sort of ANSI standard or anything, despite Rust being a reasonably mature language.

Google sought ECMA standardization when they took on Dart. Go language has an official specification, so someone could hypothetically re-implement it if they wanted to, and remain compatible Go projects.

Mozilla only wants Mozilla to be involved with Rust. They want everybody to use it in their systems, and have no input on where the language should go.

10y agoHN ↗

Really? The Rust community has been one of the most open and encouraging ones I've seen. They've also taken great pains to make sure that community feedback is solicited and incorporated.

10y agoHN ↗

From the little research I have done into Rust it seems unsurprising that there isn't a formal definition as any Rust standard would be similar in value to Haskell 2010. Useful but not sufficient due to the language still evolving.

10y agoHN ↗

This comment is beyond uninformed. Rust is currently working towards standardization, starting with the memory model. See http://smallcultfollowing.com/babysteps/blog/2016/05/23/unsa... . This work is being undertaken by Niko Matsakis (a Mozilla employee, so yes, Mozilla cares about standardization) and Nicole Mazzuca (an independent volunteer, so yes, Rust takes broad input from the community).

As for "they want everybody to use it in their systems, and have no input on where the language should go", you appear to be utterly clueless about how Rust is developed. Enormous swaths of the language have been designed by contributors who just showed up out of the blue and started putting in elbow grease. Iterators. Every data structure in the stdlib. Crucial, fundamental details of how the borrow checker operates. There's an entire repository for allowing anyone to propose changes to the language (a process which Mozilla employees are also forced to follow), which is a model that several other open source projects have since adopted (e.g. Swift).

10y agoHN ↗

I am surprised you never found managing those risks as stimulating. I do. 'C' is pretty good at providing the furniture needed to enforce formal constraints.

10y agoHN ↗

Language extension for maintenance of legacy application sounds a little bullsh1t to me.

0) If the application needs checks on anything (at the cost of performance) then higher level language (like C++) should be chosen at design time. No use for new application. 1) Existing applications will NOT port directly. Real-life applications are tightly coupled with supported compiler(s), so the compiler would need the update. Errors/exceptions (like overflows) would need handling and changes in logic. It could only deny read/write from illegal area, but without the feedback. The speed is also a major thing. Boundary check could possible prevent some bugs, but the performance will drop dramatically (example: commonly used libs like OpenSSL).

One use case I see is to add an extension (like GCC's for instance) for an existing compiler which does this. User could build a slower debug application and spot the silent errors during testing. An implementation thing, not the language extension.

10y agoHN ↗

I had a go at this problem, backwards-compatible safe C, back in 2012.[1] It was discussed on the C standards mailing list, and the consensus was that it would work technically, but was politically infeasible. What I proposed was not too far from "Checked C", but the syntax was different.

I'd defined a "strict mode" for C. The first step was to add C++ references to C. The second step was to make arrays first-class objects, instead of reducing them to pointers on every function call. When passing arrays around, you'd usually use references to arrays, which wouldn't lose the size information as reduction to a pointer does.

Array size information for array function parameters was required, but could be computed from other parameters. For example, UNIX/Linux "read" is usually defined as

    int read(int fd, char buf[], size_t len);

The safe version would be

    int read(int fd, &char buf[len], size_t len);

In both cases, all that's passed at run time is a pointer, but the compiler now knows that the size of the array is "len" and has something to check it against. The check can be made at both call and entry, and in many cases, can be optimized out. In general, in all the places in C where you'd describe an array with a pointer with empty brackets, as with "buf[]", you'd now have to put in a size expression.

You could do pointer arithmetic, but only if the pointer had been initialized from an array, and was attached to that array for the life of the pointer.

    char s[100];
    char* p = s;
    ...
    char ch = *p++;

Because p is associated only with s, the compiler knows what to check it against.

There was more, but that's the general idea. A key point was that the run-time representation didn't change; there were no "fat pointers". Thus, you could intermix strict and non-strict compilation units, and gradually convert a working program to strict mode.

This took less new syntax and fewer new keywords than "Checked C". I was trying to keep C style, adding just enough that you could talk about arrays properly in C.

[1] http://www.animats.com/papers/languages/safearraysforc43.pdf

10y agoHN ↗

Perl introduced a "strict" mode a long time ago. Although it doesn't force it on you, virtually all modern Perl programmers use it by default.

As an extra security feature Perl also supports "taint" mode, which "taints" all user-supplied data as potentially hazardous to the program. This was used more for CGI, but it's still a simple and powerful security feature. Unfortunately, it was never adopted like 'use strict' was because it would more often get in the way of the programmer.

10y agoHN ↗

"strict mode" is an assistance to migration.

The fundamental memory safety problem in C is that arrays are not first-class objects. They degrade to pointers when passed around. Yet any function which references an array has to know how big it is. Somehow. The language has no syntax for this. That's the big problem, and what I was addressing.

10y agoHN ↗

I wasn't arguing your point. I'm saying it's been proven that some new optional functionality can be adopted slowly and eventually become de-facto standard. (And that it might not get adopted if it gets in a programmer's way)

10y agoHN ↗

I've already been downvoted for this question, but I don't get the business case here. If you are worried about this, why not write code in modern C++ which has plenty of ways to make all sorts of issues like this safe ? Why stick to C at all?

10y agoHN ↗

C++ doesn't solve the problem. C++ papers over the problem with templates. You can still get raw pointers out of C++ objects, and for most APIs, you have to. The underlying language objects are still unsafe.

10y agoHN ↗

ok, so write C++ classes that don't let you access raw pointers. I mean I understand that C/C++ languages are less safe than, say, Java - but that is the whole point. The lesser safety gives you better performance. If you don't care about bleeding edge performance, you should probably choose Java or Python or some other language that is much more flexible and easier to use

10y agoHN ↗

The lesser safety gives you better performance.

No. That excuse has been bandied about for years, but it's wrong, as we're now seeing as Rust gets better. C's problems with arrays come from lack of expressive power in the language. C doesn't even let you talk about array size in parameters.

Many of C's painful design decisions come from trying to cram a compiler into a PDP-11 with 128KB (not MB) of memory for a process. Global analysis on a machine that small while retaining reasonable compile times was hopeless. This is no longer a limitation.

10y agoHN ↗

I think the thing is that the problems people are still using C to solve for are a different than the ones where people are using C++, Java, C#. Meaning if C++ was a better option then people would have switched to using C++ two decades ago. Yet C has historical deficiencies that could be fixed by smallish mostly painless extensions to the language.

10y agoHN ↗

My guess is you would still be able to get raw pointers out of any backwards-compatible extension to C?

10y agoHN ↗

The success of the game developer industry is ignored in more conservative industries.

I just used C++ for a script last month and I got a glorious increase in performance.

Not to mention that C++11 is, in contrast with C++98, a joy to write.

10y agoHN ↗

So databases and browsers are "system software" now?