News for hackers. Stuff that matters.
Re:The cost of forsaking C by Nursie on Wednesday October 05, 2016 @05:24AM (#12642552)
Ah, C, the love of my life...

Want minimal syntactic sugar and a language that's not prone to feature-of-the-week hipsterism? C

Want to make tiny binaries for some obscure system with virtually no storage or RAM? C.

Want to know where every last cycle goes and explicitly control everything? C

Want to trivially import any of the huge array of existing libraries? You guessed it...

Want to do something you really shouldn't, and any 'sensible' language might attempt to stop, but is called for right here and now...

It's not the safest language, it's not the most expressive, but the syntax is small enough to hold in your head and the body of existing, available work is HUGE. I've been working in C for 15 years and, while I enjoy forays into other languages, it will always be my love.

Re:The cost of forsaking C by atilaneves on Wednesday October 05, 2016 @08:38AM (#12643249)
> Want to make tiny binaries for some obscure system with virtually no storage or RAM?

C++, D, Rust, ...

> Want to trivially import any of the huge array of existing libraries? You guessed it...

If C can talk to it, so can anything else. Granted, having the preprocessor means no bindings, but C++ has that too.

> Want to do something you really shouldn't, and any 'sensible' language might attempt to stop, but is called for right here and now...

C++, D.

Want undefined behaviour? C. Want segfaults? C. Want memory leaks? C. Want memory corruption? C. Want to write insecure code? C. Want to write your own containers? C. Want Go's approach to generics? C. Want to spend 3x as much time writing code as a comparable C++ solution (not to mention more productive languages)? C.

I've known C for 21 years now. I just quit a job as a C programmer for embedded systems. If I can help it, never again.

Re:The cost of forsaking C by S_I on Wednesday October 05, 2016 @09:14AM (#12643493)
>Want undefined behaviour? C. Want segfaults? C. Want memory leaks? C. Want memory corruption? C. Want to write insecure code? C.

Want all of that and a whole bag of inconsistent design choices? C++. Because, yes, one day you will meet a C++ codebase which is a mixture of "forbidden C++" and "modern C++".

Re:The cost of forsaking C by existencebox on Wednesday October 05, 2016 @12:25PM (#12645298)
For the last decade or so writing physics engines has been a hobby project of mine; I shamefully read your comment and realized that absolutely describes my current toy. It's been in various stages of dev since c++11 was newfangled, and combined with being the "learning experience" of a programmer moving over from C; let's just say it shows... (mentally revising my plans to ever apply to C++ jobs and not just go hide in a forest)
Re:The cost of forsaking C by Nursie on Wednesday October 05, 2016 @09:34AM (#12643618)
Writing C++ is three times as fast?

Perhaps so, but reading it back takes 5 times as long.

Re:The cost of forsaking C by ArkyBeagle on Wednesday October 05, 2016 @05:29PM (#12648072)
No, not for similarly skilled writers. And C++ pushes certain pathologies into much more opaque, dark corners.
Re:The cost of forsaking C by StavrosK on Wednesday October 05, 2016 @09:56AM (#12643802)
> Want to spend 3x as much time writing code as a comparable C++ solution

Coming from Python and dabbling in C for embedded software, this is the one that gets me the most. It's so frustrating to be spending hours doing something you can do with one line of the regex library in Python...

Re:The cost of forsaking C by jackhack on Wednesday October 05, 2016 @11:58AM (#12644980)
I don't understand your complaint. There are mature regex libraries for C found with the obvious Google search. Source code included. Why would you not just pick and consume one, as you would in Python?

Overall though I think what you may be seeing is simply the stratification of software development; what began in the 70s and 80s has come to fruition. There are different planes of existence, like thermoclines in the oceans. A developer may (and is likely to) live in one forever, without crossing above or below. Each has its purpose. While I wrote my own database and rendering engines in the 80s as part of applications development, I wouldn't dream of it today unless there was a very, very good reason. Same goes for network stacks. Or math libraries. Memory managers. Etc.

Sure, coming from the Python ecosystem, you will feel as though there is a shortage of auto-pilot-like assistance, but you must realize you are in a very different world now - Embedded work is (frequently) focused on predictability, responsiveness, efficiency, and even moreso with realtime work. You are the engineer in charge, and all the safe boundaries and cushions of the interpreted language world are now missing. Want to REALLY feel naked? Drop down to assembly on any platform and try to emit a simple "hello world." For those who have never done so, it's a humbling experience but rewarding.

Remember that C was designed as a "universal assembly language", easily portable to different architectures and close (enough) to the metal so the programmer can have full control over the machine. Best analogy I've heard: C is like a chainsaw - used carelessly one can cause enormous damage and destruction, but in the hands of a skilled/experienced craftsman, very clever solutions are possible.

Re:The cost of forsaking C by StavrosK on Wednesday October 05, 2016 @01:03PM (#12645643)
> I don't understand your complaint. There are mature regex libraries for C found with the obvious Google search. Source code included. Why would you not just pick and consume one, as you would in Python?

Mostly because I'm used to one single place for libraries (PyPI) and I don't know how to find (and evaluate) libraries in C. I also don't know if they'll run on my MCU or how much RAM they require. I have found one or two embedded regex libraries, but they were very limited in what they could do or failed some other criterion.

Besides, that was just an example, it's just death by a thousand cuts with similar things one after the other.

Re:The cost of forsaking C by kkarakk on Thursday October 06, 2016 @08:46AM (#12651934)
-I don't know how to find (and evaluate) libraries in C

you can replace C with any language. you're evangelising about the toolbox you know instead of learning about the hammer you are familiar with and don't want to learn how to operate

Re:The cost of forsaking C by StavrosK on Sunday October 09, 2016 @04:48PM (#12673385)
Alright, I'm game. Where's the C library repository, and what's the manager I can use to handle dependencies automatically?
Re:The cost of forsaking C by meej on Wednesday October 05, 2016 @07:41PM (#12648940)
> Why would you not just pick and consume one, as you would in Python?

You probably wouldn't do that in Python; the regular expressions module is part of the language.

Re:The cost of forsaking C by protomok on Wednesday October 05, 2016 @12:58PM (#12645602)
An alternative to the suggestion to use a regex C library is to embed Lua code into your C code. Lua+C is great for resource constrained embedded systems and can make text parsing a lot less painful than using pure C.

The Lua docs provide some examples of integrating Lua into C here - https://www.lua.org/pil/24.1.html.

Re:The cost of forsaking C by StavrosK on Wednesday October 05, 2016 @01:00PM (#12645630)
The problem there is that usually you're constrained to 2 kb of RAM or so for an Arduino, so that's too heavyweight :/ Plus, it's outside my abilities currently, sadly.
Re:The cost of forsaking C by krylon on Wednesday October 05, 2016 @03:16PM (#12646860)
> Plus, it's outside my abilities currently, sadly.

If your target only has two KB of RAM, Lua is a no-go, I guess. But skill-wise, I can highly recommend it. The reference manual is very well-written, the Lua language itself is very nice and easy to learn, and Lua's C interface is very pleasant to use; and again: the documentation is very good. (Also, the community is very friendly!)

If you ever take a shot at it, the Lua Users Wiki (http://lua-users.org/wiki/) is a good starting point.

Re:The cost of forsaking C by StavrosK on Wednesday October 05, 2016 @06:45PM (#12648611)
Hmm, the example you posted doesn't actually look very complicated at all! And I agree, Lua is a very nice language, I've used it for other projects.
Re:The cost of forsaking C by ArkyBeagle on Wednesday October 05, 2016 @05:31PM (#12648092)
Perhaps because I've done it all my adult life, I've never understood how text manipulation in 'C' is all that painful.
Re:The cost of forsaking C by Nursie on Wednesday October 05, 2016 @10:08AM (#12643903)
I love python too. It's my favourite language for getting stuff done fast.

However it doesn't give you the control or the performance of C without some serious work, some of which is usually work in C!

Re:The cost of forsaking C by bluejekyll on Wednesday October 05, 2016 @11:31AM (#12644691)
Python let's you get stuff done fast, but it's almost more dangerous than C in some respects. Without a compiler, you run the risk of deploying code that will not run, and you don't know until that section of code is actually executed. Requiring a massive set of tests to actually validate your code.

On top of the additional testing, you also will have a performance problem at some point after success. And then people will discuss or even plan for a rewrite in a more performant, language. But we all know that rewrites usually fail to materialize. PoC's turn into products, products turn into companies, and companies bottom lines can't generally spare time and money to rewrite the entire service.

I'm not advocating for C, but I wouldn't put Python up as a comparable thing.

Re:The cost of forsaking C by dragonwriter on Wednesday October 05, 2016 @01:00PM (#12645625)
> Python let's you get stuff done fast, but it's almost more dangerous than C in some respects. Without a compiler, you run the risk of deploying code that will not run

C code that compiles can and does blow up at runtime.

There are languages whose type systems do go a long way toward minimizing the risk of this happening, but C is not really one of them.

Re:The cost of forsaking C by bluejekyll on Wednesday October 05, 2016 @05:01PM (#12647840)
I completely agree. C sucks at runtime. I was trying to point out that Python sucks at runtime too.

I personally wouldn't choose either language for a new project.

Re:The cost of forsaking C by witty_username on Wednesday October 05, 2016 @12:52PM (#12645551)
Having the correct type doesn't guarantee correctness.

As a noob C programmer, in my programs segfaults often occur along with undefined behaviour (which is much worse, as your program will silently give the wrong output).

While in Python, you'd get a traceback which is much easier to debug.

> Requiring a massive set of tests to actually validate your code.

Both require tests to validate your code. Sure, static typing can verify some trivial mistakes, but they can't check that array accesses are in bounds, integer overflow, etc.

Re:The cost of forsaking C by kruczek on Thursday October 06, 2016 @09:02AM (#12652047)
> As a noob C programmer, in my programs segfaults often occur along with undefined behaviour (which is much worse, as your program will silently give the wrong output).

> While in Python, you'd get a traceback which is much easier to debug.

Well, C's segfault will also generate core dump, which is essentially the same thing as Python's traceback - it tells you where the program crashed.

Re:The cost of forsaking C by StavrosK on Wednesday October 05, 2016 @01:04PM (#12645655)
You're actually talking about typed vs untyped, which isn't so much about C vs Python. Python is slowly acquiring static type checking (and it's working rather well nowadays).
Re:The cost of forsaking C by bluejekyll on Wednesday October 05, 2016 @04:59PM (#12647815)
Yes, I should have been clearer that this wasn't in support of C over Python. I'm commenting on the relative safety of Python and the downstream costs of using it.

C is not typesafe either, and blows up for other reasons at runtime.

Re:The cost of forsaking C by StavrosK on Wednesday October 05, 2016 @06:46PM (#12648619)
Yep, agreed. I'm very excited about the optional type checking in Python, and can't wait for it to improve so I can use it in all my projects.
Re:The cost of forsaking C by dr_zoidberg on Wednesday October 05, 2016 @01:11PM (#12645723)
Give Cython a try, you can get huge gains in memory/speed by carefully transitioning from Python to C with it. (Or use it to "write C in Cython"[0])

[0] https://explosion.ai/blog/writing-c-in-cython

Re:The cost of forsaking C by Grishnakh on Wednesday October 05, 2016 @04:01PM (#12647284)
This is why (depending on exactly where in the stack you're working, and on what kind of device; I'm assuming you're developing a graphical application on an embedded device with an ARM-like CPU and a small screen for this example) you should be using Qt Embedded. It's C++, and has a very good regex library. You get the power and speed of C++ and all kinds of nice features like regexes.
Re:The cost of forsaking C by EpicEng on Wednesday October 05, 2016 @05:52PM (#12648247)
Sure, but you're giving up control. There's a trade-off and there is a whole world of things which simply aren't practice to do in Python, but work just fine in C.
Re:The cost of forsaking C by ArkyBeagle on Wednesday October 05, 2016 @05:30PM (#12648084)
It's (nearly) trivial to write FSM in 'C' that do what regexp do in Python.
Re:The cost of forsaking C by kps on Wednesday October 05, 2016 @06:03PM (#12648342)
Yes, if you're matching constant regular expressions on an embedded device using a general-purpose runtime regular expression processor, you're probably Doing It Wrong™.
Re:The cost of forsaking C by bkjsbkjdnf on Wednesday October 05, 2016 @10:03AM (#12643862)
There are regex libraries for C. Worst argument so far.
Re:The cost of forsaking C by coldtea on Wednesday October 05, 2016 @12:02PM (#12645034)
>There are regex libraries for C

Which everybody here knows and nobody doubted. So, a big duh!

What the parent means is with Python you don't need to go and install one, adjust your makefiles, etc. Regex are right there in the standard library, and things that are not are immediately usable in just a "pip install" away.

Re:The cost of forsaking C by StavrosK on Wednesday October 05, 2016 @01:05PM (#12645672)
Exactly. The biggest problem I have is just finding appropriate libraries. With PyPI I know where they are, how to get them and which one is popular. With C, I'm completely lost. I use PlatformIO's manager, but it's limited to embedded libraries, so I just don't know where to find things at all.
Re:The cost of forsaking C by Manishearth on Wednesday October 05, 2016 @10:45PM (#12649841)
Its not just finding the libraries, its also marrying the makefiles.
Re:The cost of forsaking C by anthk on Thursday October 06, 2016 @08:48AM (#12651945)
With Linux that's trivial to know.
Re:The cost of forsaking C by EpicEng on Wednesday October 05, 2016 @07:02PM (#12648719)
...google
Re:The cost of forsaking C by EpicEng on Wednesday October 05, 2016 @07:02PM (#12648716)
Sure, and to get that Python requires a big runtime to be present wherever it goes. Trade-off.
Re:The cost of forsaking C by snakeanus on Thursday October 06, 2016 @09:42AM (#12652338)
apt-get install Done!

Do people actually use pip when you can just use the package manager of your distro?

Re:The cost of forsaking C by majewsky on Wednesday October 05, 2016 @10:15AM (#12643960)
I would upvote this if it weren't for the second sentence.
Re:The cost of forsaking C by ixtli on Wednesday October 05, 2016 @10:59AM (#12644342)
I think it's a bad thing that hacker news is so allergic to strong editorialization.
Re:The cost of forsaking C by lemmings19 on Wednesday October 05, 2016 @11:55AM (#12644949)
I do not. There is enough of it elsewhere on the web, it's nice to be somewhere relatively free of it for a change.

The conversations that occur here generally seem much more structured.

Re:The cost of forsaking C by ixtli on Wednesday October 05, 2016 @02:36PM (#12646523)
I agree that they are more structured, but I don't see any evidence that this is in any way due to how immediately people are attacked for wording things strongly.

Engineering is a life and death business more often than people think; it deserves people who feel strongly about it.

As an aside, I think the rules about trolling and personal attacks are pretty clear and easy to enforce. What I'm specifically concerned about is that those rules are evoked outside of the spirit in which they were created to attack emphasis in general. In fact, most of the discussion here is in clear violation of "Please avoid introducing classic flamewar topics unless you have something genuinely new to say about them." but obviously we rightly care a lot about this topic and, since people are acting like adults, no one needs to tap on the poster so to speak.

Re:The cost of forsaking C by lemmings19 on Wednesday October 05, 2016 @07:34PM (#12648901)
It looks like we agree that attacks are not helpful, but freedom of expression can be.

I appreciate that the majority of people in this forum express their opinions in a highly productive manner void of animosity, as you've just demonstrated. The previous's user's remark "Worst argument so far." did not convey this spirit. Whether intentionally or not, antipathy and pure negativity do not bring out the best of people in online forums. It is my hope that those are two things which this community seeks to discourage, but not all freedom of expression. This is how I interpreted the comment which sparked your initial response.

Re:The cost of forsaking C by microcolonel on Wednesday October 05, 2016 @12:08PM (#12645088)
D? You sure you can get a compiler for that on an "obscure platform"? Do the libraries you want to use work when the GC is off?
Re:The cost of forsaking C by atilaneves on Wednesday October 05, 2016 @07:26PM (#12648848)
You can use D on platforms LLVM amd gcc support. Some libraries work, some don't. Stick @nogc on main and you're guaranteed to not use the GC. Besides, on constrained systems you're not going to be wanting many dependencies.
Re:The cost of forsaking C by chias on Wednesday October 05, 2016 @12:22PM (#12645266)
I love Rust with a passion, but in all fairness it does not make tiny binaries. On my system, hello world in C is 6.5k, hello world in Rust is 805k (124 times bigger). After running 'strip' on the binaries it's a little better: 4.3k vs 345k, which is better but is still 80 times bigger.

(I know there are some "tricks" you can use to make smaller Rust binaries by chopping things out, but of course the same applies to C. For example, I can take the C binary and just truncate the file down to 2230 bytes without breaking it)

Re:The cost of forsaking C by Gankro on Wednesday October 05, 2016 @12:41PM (#12645449)
Hello world is large primarily because it statically links in jemalloc and libunwind, which are obviously fixed overhead. Both can be removed (and indeed I would expect jemalloc to be turned off by default sometime soon because each jemalloc release seems to be less stable than the last). If you do this you'll get a much healthier binary size.

C binaries are small because they're assuming you've installed what is ultimately the C runtime on your system (libc).

Re:The cost of forsaking C by dbaupp on Wednesday October 05, 2016 @12:40PM (#12645432)
A direct comparison like that is somewhat comparing apples to oranges. Don't get me wrong, defaults matter, but Rust still does offer the control required to get small binaries, and, those defaults are not nearly as bad for low-level domains where one isn't using the standard library, which is where binary size is most critical. See also https://lifthrasiir.github.io/rustlog/why-is-a-rust-executab... and even http://mainisusuallyafunction.blogspot.com/2015/01/151-byte-... .
Re:The cost of forsaking C by Manishearth on Wednesday October 05, 2016 @10:41PM (#12649814)
Those aren't tricks. Rust does not choose the same defaults as C, and, among other things, statically links to the stdlib and jemalloc.

The tricks you describe are just changing the compile options to those that C uses by default.

on top of that you can apply the same tricks as C; e.g. by running strip, truncating the binary, writing a linker script, etc.

Re:The cost of forsaking C by steveklabnik on Wednesday October 05, 2016 @12:36PM (#12645401)
You're not comparing apples and oranges there.

For more: https://lifthrasiir.github.io/rustlog/why-is-a-rust-executab...

Re:The cost of forsaking C by themihai on Wednesday October 05, 2016 @12:18PM (#12645215)
You forgot to respond to the first one: "Want minimal syntactic sugar and a language that's not prone to feature-of-the-week hipsterism"
Re:The cost of forsaking C by oldmanjay on Wednesday October 05, 2016 @12:26PM (#12645312)
That's a lot of words to declare oneself a masochist

Or if being verbose is desired, do you want to do a job for a computer that you are not suited to do but the computer is?

Re:The cost of forsaking C by atilaneves on Wednesday October 05, 2016 @07:23PM (#12648836)
I didn't forget to respond. I consider minimal syntactic sugar a big, not a feature.
Re:The cost of forsaking C by snakeanus on Thursday October 06, 2016 @09:44AM (#12652356)
The answer to this is Scheme.
Re:The cost of forsaking C by coldtea on Wednesday October 05, 2016 @01:35PM (#12645929)
Why in God's name would I want minimal syntactic sugar?

I want optimal syntactic sugar.

Re:The cost of forsaking C by EpicEng on Wednesday October 05, 2016 @05:51PM (#12648239)
Everyone has a different idea of what 'optimal' means here.
Re:The cost of forsaking C by themihai on Wednesday October 05, 2016 @03:19PM (#12646890)
> I want optimal syntatic sugar

Like Rust or C++ templates? I prefer C syntax over the "optimal" alternative.

Re:The cost of forsaking C by coldtea on Wednesday October 05, 2016 @04:37PM (#12647612)
Why in god's name would Rust or C++ templates be the optimal amount (or optimal syntactic sugar design)?
Re:The cost of forsaking C by themihai on Thursday October 06, 2016 @10:39AM (#12652799)
Well, that's my point! There is no alternative with "optimal syntactic sugar design". You have to choose between something 'minimalistic' (C) and something less minimalistic (i.e. Rust).
Re:The cost of forsaking C by snakeanus on Thursday October 06, 2016 @09:59AM (#12652469)
> Want undefined behaviour? C

Can be solved by not doing stuff that are considered as undefined. Think of them as the standard's say of saying "don't do that". It's quite easy to do in most cases.

> Want segfaults? C > Want memory corruption? C > Want to write insecure code? C

There is absolutely nothing in C that makes it more prone to these in comparison to other languages. Moreover you can easily solve these by using an implementation that protects you. (such as one of the multiple C compilers that guarantee to produce safe code without UB or the sanitisers in gcc and clang)

> Want memory leaks? C

Can be easily avoided by avoiding dynamic memory allocation. Moreover nothing stops an implementation from using a GC.

> Want to write your own containers? C

This applies to all the languages as none of them happen to have an implementation of every container in their standard library. It is true that C lacks that in comparison to some other languages, however implementing the common ones (or using a library) is an extremely trivial thing to do.

> Want to spend 3x as much time writing code as a comparable C++ solution (not to mention more productive languages)? C

You must be quite the shitty C programmer to need 3 times less time to write something in C++.

Re:The cost of forsaking C by atilaneves on Thursday October 06, 2016 @12:24PM (#12653745)
> Think of them as the standard's say of saying "don't do that"

I have a list of "don't do that" rules. I still do them, usually by accident.

> There is absolutely nothing in C that makes it more prone to these in comparison to other languages

If you believe that, then there's nothing I can say that will change your mind.

> Moreover nothing stops an implementation from using a GC

Many applications can't use a GC. For tiny systems, forget it.

> none of them happen to have an implementation of every container in their standard library

That completely sidesteps the fact that in pretty much every other language the containers one would like to use 99% of the time are implemented in the standard library or the language itself.

> You must be quite the shitty C programmer to need 3 times less time to write something in C++.

Only a shitty C++ programmer _doesn't_ write code 3 times as fast as they'd write C.

Re:The cost of forsaking C by tscs37 on Wednesday October 05, 2016 @10:20AM (#12644010)
Don't drag go into this.
Re:The cost of forsaking C by bkjsbkjdnf on Wednesday October 05, 2016 @10:02AM (#12643851)
If you spend 3x the time writing equivalent code in C as you do in C++ you're either a bad C programmer, a bad C++ programmer, or likely, both.
Re:The cost of forsaking C by CyberDildonics on Wednesday October 05, 2016 @03:50PM (#12647165)
Concatenate two strings with resource management in C then C++ and see which is easier.
Re:The cost of forsaking C by ArkyBeagle on Wednesday October 05, 2016 @05:35PM (#12648116)
This is a relatively trivial thing in either - depending on how you define "with resource management." I understand completely that people want to translate patterns directly across languages, but since "string manipulation with resource management" as a delta-detail going from 'C' to say, Python was a design goal, it's somewhat specious.
Re:The cost of forsaking C by atilaneves on Wednesday October 05, 2016 @07:28PM (#12648864)
It's not trivial in C, it's a pain is what it is. I'd put it another way: if someone can't write C++ 3x faster than C they're not a very good C++ programmer. Maybe they're writing C with classes.
Re:The cost of forsaking C by ArkyBeagle on Thursday October 06, 2016 @02:13AM (#12650568)
You just won't get agreement from me here - string manipulation in 'C' is quite easy. Concatenation operators and the like mostly get in the way. This has nothing to do with design approaches. The str() suite from the standard library is very easy to use safely, if you're careful in your constraints. You do have to think "this is a buffer" and behave accordingly. The resulting code is pretty tedious, but there's no way it takes 3x as long.

Throw in the level of control with sprintf() and there's a pretty clear win.

What is easier with C++ ( and most scripting languages ) are things like combinators and regexp.

Re:The cost of forsaking C by pjmlp on Thursday October 06, 2016 @02:59AM (#12650705)
The CVE database shows how easy it is to use correctly, bah.
Re:The cost of forsaking C by MaulingMonkey on Thursday October 06, 2016 @11:59AM (#12653526)
Warts like no guaranteed NUL termination for strncpy and strncat if the buffer length is reached are especially fun to contend with in code reviews.

As is *cat being O(N) with respect to destination length.

So easy that there's been constant flamewars over nonstandard alternatives such as strlcpy, strcpy_s... https://news.ycombinator.com/item?id=6940368

Re:The cost of forsaking C by atilaneves on Thursday October 06, 2016 @12:27PM (#12653765)
I actually can't picture a universe in which there'd be a clear win manipulating strings in C. If you believe that and have done string manipulation in other languages, then you're a very different person from me and nothing I can say or do will change your mind. We'll have to agree to disagree.
Re:The cost of forsaking C by Keyframe on Wednesday October 05, 2016 @08:58AM (#12643382)
As if it were yesterday. Late 89 or early 90, I was learning my first programming language properly (after Logo, BASIC and other stuff). It was C. Common wisdom was that C was bloat and you'd do everything in assembly anyways. I stuck to it (did asm as well). Then, a few years later everything changed with real bloat that was C++ of ye olde and C was back in full force and never quit being there. I've dabbled with C++ before STL craze and never went into it as some of my friends did, but it wasn't quite different. Just a different mental model that it evangelised. These days, I can't even tell what's going on when looking at modern C++. I'm not sure I even want to. C just works for me, and has for a long time.

I've worked in numerous languages and platforms, even changed careers from programming (graphics) to film and television. But I'll always be a C programmer.

Re:The cost of forsaking C by retro64 on Wednesday October 05, 2016 @11:17AM (#12644534)
I have been coding in straight C lately on an embedded personal project and have loved it immensely. I know what is going on and have a good shot at predicting the resulting assembly.

However, for me, C falls down on large projects. I know there a lot of hate on objects lately, but the complexity of a project decreases while the maintainability increases when you use properly designed interfaces. You “force” the new guy to do it right because the interface makes it obvious. I know there are ways to enforce encapsulation with C, but I’ve never worked on a (large) codebase where this has been successful.

Re:The cost of forsaking C by Keyframe on Wednesday October 05, 2016 @11:43AM (#12644818)
Objects are in C as well, with structures. You can do abstraction like that in different ways in comparison to classes. For example, components are common. Difference being that objects are components, but not all components are objects. Also function objects, aka functors.

I try to organize into specific components and piece them together into a sequential or threaded or both model, depending on what I do. Of course, it is specific to what I do. But there are large C projects that are successful - for example, Linux kernel.

Re:The cost of forsaking C by pjmlp on Thursday October 06, 2016 @03:03AM (#12650716)
And yet, in spite of all code reviews, they just got an use after free exploit this week and the CVE database is full of exploits due to memory corruption.
Re:The cost of forsaking C by CyberDildonics on Wednesday October 05, 2016 @03:56PM (#12647223)
I've encountered a lot of C programmers who feel that C++ is silly nonsense.

C++11 really does put that to rest. Move semantics basically enable complete avoidance of manual memory management. There are many other powerful and convenient aspects, but in C++11 and on managing memory essentially goes away. I essentially never allocate memory explicitly.

Re:The cost of forsaking C by Keyframe on Thursday October 06, 2016 @04:52AM (#12651043)
I essentially never allocate memory explicitly

Depends on what you do, I guess. I process huge image sequences and have them run (play at least) in real time. I cannot afford to not allocate memory manually. In fact, I have to and I have to manage heap myself. I also have to manage thread affinity, in order to have threads (producer/consumer) share L2 cache to get the speed I want, and all that on multiple processors.

Sometimes you must do that manually.

Re:The cost of forsaking C by CyberDildonics on Thursday October 06, 2016 @10:43AM (#12652832)
> Sometimes you must do that manually.

You say that, but I deal with almost the exact same things. What I mean by manual is something like malloc where the freeing of memory is manual. Sean Parent would call this 'no raw pointers'.

For starters, the fact that memory allocation is even an issue seems odd to me, I'm not sure why you wouldn't allocate large chunks of memory rarely.

Even if there are OS specific calls I'm making to deal with special memory, I make sure it is wrapped with some simple class or struct that has a destructor and likely a move constructor. Alignment issues can be wrapped as well, then there is no doubt who owns the memory, who frees it, and where/when it is freed. I've never seen a situation in which raw malloc/free are necessary or any control is lost using C++.

I doubt you suddenly want to use C++ still, I'm willing to bet you know C extremely well, but at least realize that your choices are not based off of technical reasons.

Re:The cost of forsaking C by Keyframe on Thursday October 06, 2016 @04:12PM (#12655694)
Oh, I malloc from OS or hardware (external custom hardware) rarely. Usually once, a big chunk at the start and then heap manage manually. Well, semi-manually too since I took most of my idioms into a library of mine. I had a lapse of thought. Keeping everything aligned is not an issue these days. Affinity can also be done from other languages if OS supports it (looking at you, MacOS), intrinsics or asm directly also, etc.

One thing is sure though. You're right most of reasons aren't technical. I'm very confident about what I know and what I don't know in C and I don't have to second-guess (usually) what I want to do, because my experience lies with C. It's a subjective choice, but also a technical - since that knowledge and experience is my technical asset. It's not like you can't do something in C that you can't do in C++. In fact, you can do it almost the same if you want to, but with C++ you would be a better fit if you follow C++ idioms, which I haven't picked up over the years (especially after STL cambrian explosion) and something I think I won't in the near future. Reason is simple. Everything I do, I do mostly alone and so far C has been good to me. I venture into other things, out of curiosity and sometimes necessity, but I always kind of fall back to C. Sometimes it's due to the fact that I know of top of my head how to do something quick (which I often need to) without resorting to googling or I don't know how to make it run quick enough since I'm not intimate with the language (not C++ in this case, but in general).

Re:The cost of forsaking C by jbb555 on Wednesday October 05, 2016 @05:39AM (#12642605)
Agree entirely with all this.

You know what you get with C and it just works as you expect always. I always feel refreshed after writing C.

There are perhaps a few very minor enhancements I'd suggest, but I'd be very reluctant to open the floodgates and ruin it.

Re:The cost of forsaking C by zigzigzag on Wednesday October 05, 2016 @05:43AM (#12642617)
It always works as you expect? Really?

C is one of the few languages, along with C++, that revels in undefined behaviour. It can be very hard to reliably know what a C program will do if it's not written very carefully because there are so many constructs that look benign but which are technically wrong, and the compiler will mercilessly exploit in order to optimise your program into nonsense.

Re:The cost of forsaking C by deagler on Wednesday October 05, 2016 @05:57AM (#12642666)
This, While C and C++ are both very powerful languages and could still be considered the "industry standard"(loosely used) It is definitely not a language that will make your applications work as expected, I would say that C#/Java or higher level scripting languages like Lua or Javascript are languages that will let you make "code it and it works" applications
Re:The cost of forsaking C by MaulingMonkey on Wednesday October 05, 2016 @06:48AM (#12642833)
C and C++ are the only languages I regularly use wherein I need to resort to disassembly to debug the damn thing.
Re:The cost of forsaking C by retro64 on Wednesday October 05, 2016 @11:26AM (#12644635)
I find this statement hard to imagine. I've been coding professionally in C++ for just shy of 20 years now (and in C for a few years before that) and have only resorted to assembly when I needed to actually use assembly for performance reasons.

Actually - not completely true. I do like to look at the assembly from time to time for other reasons, but this is rare.

Re:The cost of forsaking C by MaulingMonkey on Wednesday October 05, 2016 @02:08PM (#12646256)
Even when I have performance to worry about, intrinsics are usually an option - possibly even a superior option - when writing performance sensitive code. But here are some of the cases where I resort to looking at program disassembly - I'll note a theme here of debugging optimized code (because who doesn't love heisenbugs):

1) Diagnosing a crash which turned out to be the result of a 1 byte vtable pointer corruption bug in an older codebase, which turned out to be a bad static_cast in relatively removed code (a good case for boost::polymorphic_downcast!). Simply understanding which pointer was bad in the first place required looking at the disassembly - when you can't rely on your debugger's results thanks to optimization.

2) Figuring out the actual values of variables in crashes and crash dumps of optimized builds to properly root cause a bug, when the debugger gets confused - or simply aggressively inlined and reordered everything so aggressively that there's no sensible values to even display (so, most crash dumps.)

3) Noticing when the optimizer has reordered code "unexpectedly", alerting me to the fact that supposedly thread safe code is in fact nowhere nearly remotely safe and is in fact missing many memory barriers (possibly because their portable macros "helpfully" defaulted to a noop on whatever new and previously unrecognized platform I'm porting to.)

4) Noticing when the optimizer has removed or rewritten code in an "incorrect" manner, helping me debug code that would've worked if it hadn't technically invoked undefined behavior, so I can a) fix it, b) attempt to explain to my coworker that, yes, it's really undefined behavior, and yes, it's actually a problem (typically with a combination of citing the standard and linking INVALID WONTFIX-ed "bugs" in some compiler's bug database), c) be reasonably certain I've actually found the real root cause of a bug and fixed it.

Now, yes, I'll admit this isn't 100% of my debugging sessions. And perhaps I'm an outlier. My coworkers generally learn that I can (eventually) tackle pretty much any weird bug they might be struggling with and that I'm happy to help. All the porting I've done reopens a whole codebase's worth of wounds - latent undefined behavior that another compiler's optimizer didn't take advantage of.

But on the other hand, I've been lucky enough to never encounter a codegen bug in all the compiler and linker bugs I've found. So far. That I know of. And while "rare" by incidence, these are the debugging sessions that can eat weeks at a time for a single bug, when sufficiently nasty and novel.

Re:The cost of forsaking C by kbart on Wednesday October 05, 2016 @07:06AM (#12642890)
"It always works as you expect? Really?"

Well, it works as defined in standards. It's just not every programmer knows what to expect. C is simple, yet powerful language and with powers comes responsibility. It's not like you can throw some libraries/modules/objects (or whatever it is in other, safe languages) together, upload to server and call it a day -- static testing, debugging, unit testing is a vital part of any semi serious C project.

Re:The cost of forsaking C by JoeAltmaier on Wednesday October 05, 2016 @09:38AM (#12643652)
I hear this, but I've rarely experienced it. Maybe I unconsciously avoid such cases with long use. I started with assembler, and debug C/C++ with disassembly turned on, so maybe that's why.
Re:The cost of forsaking C by ArkyBeagle on Wednesday October 05, 2016 @05:37PM (#12648129)
It's just really not that hard to avoid undefined behavior. Really. The worst is arguably integer overflow, and that's not even all that challenging.
Re:The cost of forsaking C by 0xfeba on Wednesday October 05, 2016 @09:26AM (#12643563)
C++ is far more prone to undefined behaviour and even compilation across systems with the STL.
Re:The cost of forsaking C by tarancato on Wednesday October 05, 2016 @06:33AM (#12642776)
Undefined behaviour is not as prevalent in real world code as reading articles from HN might make you think.
Re:The cost of forsaking C by rwmj on Wednesday October 05, 2016 @07:01AM (#12642875)
This is a very naive statement. Sure there are a handful of good companies that enable every single compiler warning, and fix those warnings, and then run the code through Coverity, and fix all those problems too. Almost no one else does. The amount of terrible C in the real world is enormous.
Re:The cost of forsaking C by w0utert on Wednesday October 05, 2016 @07:41AM (#12643013)
>> Sure there are a handful of good companies that enable every single compiler warning.

You think so? Every company I've worked for, or that I've known people that worked there, always enabled -Wall for their C and C++ code. Most OSS software compiles with all warnings enabled.

I think the issue with undefined behavior in C/C++ is extremely overblown, aside from fun academic examples like 'what does i++++i++ evaluate to' there isn't actually all that much undefined behavior or gotchas in C/C++. I would say there are less, compared to other languages I know.

Re:The cost of forsaking C by rwmj on Wednesday October 05, 2016 @08:24AM (#12643168)
Signed overflow problems are everywhere, even in carefully written code. Using 'int' instead of a more specific type is a code smell. Security code which presumes that because you wrote ptr != NULL, that the check is actually carried out. Code that does type punning. Code that doesn't know about aliasing. It goes on and on.

You need to know that the problem exists in order to know that you have a problem. There are many C programmers who learned C back in the 1980s who don't even realize these are issues.

Re:The cost of forsaking C by tarancato on Wednesday October 05, 2016 @08:33AM (#12643220)
I'd say things have changed quite a bit since format string bugs...
Re:The cost of forsaking C by MaulingMonkey on Wednesday October 05, 2016 @08:50AM (#12643335)
Since?

I'm still adding the compiler specific annotations to add format string checking to custom variadic logging functions in codebases I inherit, and finding multiple bugs.

Re:The cost of forsaking C by majewsky on Wednesday October 05, 2016 @10:17AM (#12643980)
> always enabled -Wall for their C and C++ code

Of course you want -Wall -Wextra -Werror -pedantic. ;)

Re:The cost of forsaking C by david-given on Wednesday October 05, 2016 @11:03AM (#12644389)
...but please, for the love of Mike, don't ship source code with -Werror.

There's nothing like the experience of trying to fix somebody else's code which compiled fine on gcc version 8.97 but which now fails to compile on gcc version 8.98 because the new compiler has some new warnings, which it's now treating as errors, and now fails to compile.

...and you've got stuff to do, and the program isn't even broken.

Re:The cost of forsaking C by wtbob on Wednesday October 05, 2016 @07:37PM (#12648913)
> … and you've got stuff to do, and the program isn't even broken.

Well, it may be — that's one of the problems with C: you never really know for sure if a warning really matters or not. But man, there sure are a lot of them!

Re:The cost of forsaking C by mitchty on Wednesday October 05, 2016 @10:58AM (#12644335)
Or if you don't have to use gcc, just -Weverything in clang.
Re:The cost of forsaking C by GFK_of_xmaspast on Wednesday October 05, 2016 @12:43PM (#12645470)
I used to work with a guy who would regularly get upset about the idea letting the compiler return warnings because he knew better and didn't want to be bothered with it.

Last I checked he has a couple hundred points on the hacker news internet forums.

Also just last week I found and reported some undefined behavior in a major c++ package that's used by almost every player in as many as several industries. I don't expect it will ever make any difference in production, but it still snuck in.

Re:The cost of forsaking C by kbart on Wednesday October 05, 2016 @07:17AM (#12642922)
"The amount of terrible C in the real world is enormous."

I'm sure you could say that about pretty much any programming language: "The amount of terrible X in the real world is enormous". There are also plenty of clean, nice, safe C code around (and any other language), there's no need to over-generalize ("Almost no one else does").

Re:The cost of forsaking C by netheril96 on Wednesday October 05, 2016 @08:34AM (#12643227)
> I'm sure you could say that about pretty much any programming language: "The amount of terrible X in the real world is enormous".

But the damage is far greater in C. In other languages you won't have arbitrary code execution or privilege escalation just because the programmer is not careful. Nor will there be, in other languages, so many nondeterministic bugs that show up once in a blue moon.

Re:The cost of forsaking C by falcolas on Wednesday October 05, 2016 @09:11AM (#12643476)
> In other languages you won't have arbitrary code execution or privilege escalation just because the programmer is not careful.

Sure you do. Remember the YAML fiasco with Ruby? How about the thousand-and-one RCE issues with PHP? eval isn't evil for no reason.

Re:The cost of forsaking C by kbart on Wednesday October 05, 2016 @09:39AM (#12643662)
"In other languages you won't have arbitrary code execution or privilege escalation just because the programmer is not careful"

No, it's possible to make system insecure with pretty much any language if programmer is not careful. SQL injection, cross-site scripting, cross-site request forgery and the list goes on..

Re:The cost of forsaking C by 0xfeba on Wednesday October 05, 2016 @09:28AM (#12643575)
Yeah, I do web development. I've worked with javascript, PHP, and, sigh, classic ASP.

There's bad code everywhere. Some languages make it a bit easier, but it's really not the languages fault.

Re:The cost of forsaking C by majewsky on Wednesday October 05, 2016 @10:18AM (#12643989)
Re:The cost of forsaking C by cwyers on Wednesday October 05, 2016 @09:37AM (#12643640)
There are very few programming languages where the total lines of code written is larger than the amount of bad C code written.
Re:The cost of forsaking C by kbart on Wednesday October 05, 2016 @09:41AM (#12643677)
There are very programming languages where the total lines of code written is even comparable to C, so of course there is more of bad code too.
Re:The cost of forsaking C by krylon on Wednesday October 05, 2016 @03:29PM (#12646981)
There are two kinds of languages: Those everyone hates and those nobody uses (according Bjarne Stroustrup, but I tend to agree... ;-) ).
Re:The cost of forsaking C by MaulingMonkey on Thursday October 06, 2016 @08:01AM (#12651710)
There's a kernel of truth there, but I find myself regularly using languages which I hate much less.

If your best defense of a language is "well, at least people use it", that's a bad sign.

Re:The cost of forsaking C by krylon on Wednesday October 12, 2016 @05:13PM (#12696451)
I always read Stroustrup's quote as saying, roughly speaking, that if nobody uses a language, nobody will notice its shortcomings, and if lots of people use it, lots of people will notice. In other words, popularity is no excuse for sucking, but if one is not popular, no one will notice how much one sucks.
Re:The cost of forsaking C by MaulingMonkey on Wednesday October 05, 2016 @08:45AM (#12643302)
You're right - it's far more prevalent, if the bug database for basically every C or C++ codebase I've ever seen is any indication.
Re:The cost of forsaking C by ArkyBeagle on Wednesday October 05, 2016 @05:38PM (#12648139)
it's a heatmap.
Re:The cost of forsaking C by CountSessine on Wednesday October 05, 2016 @02:29PM (#12646459)
There are some very interesting surveys and studies that suggest otherwise. Undefined behaviour due to integer overflow seems to be very common.

http://www.cs.utah.edu/~peterlee/papers/tosem15.pdf

Re:The cost of forsaking C by akvadrako on Wednesday October 05, 2016 @07:39AM (#12643004)
I would tend to disagree. For example, casting void * to other pointer types is undefined, but this construct is often used, for example:

  void func(void *ptr)
    {
    uint32_t *ip = ptr;
    ptr[0] = 123;
    }
Re:The cost of forsaking C by zosima on Wednesday October 05, 2016 @07:50AM (#12643050)
This is wrong. Casting to and from void * is defined for all pointer types except function pointers, according to the standard.

Otherwise most every assignment after call to malloc would be undefined.

Re:The cost of forsaking C by akvadrako on Wednesday October 05, 2016 @09:05AM (#12643431)
Yes, you are right, void * is an exception. However, any other pointer cannot be reliably casted:

From C1X, section 6.3.2.3:

"A pointer to an object type may be converted to a pointer to a different object type. If the resulting pointer is not correctly aligned for the referenced type, the behavior is undefined."

Though that is quite odd, since any pointer can be converted to void* , which only needs alignment to the char type. So converting from x* -> y* is undefined, but x* -> void* -> y* is defined.

Re:The cost of forsaking C by planteen on Wednesday October 05, 2016 @09:44AM (#12643704)
That might not necessarily work. If you have something like:

>> uint8_t x[100];

>> uint32_t *y = &x[1];

And then dereference y, most RISC architectures will trap on the unaligned access. It doesn't matter if there is an intermediate void pointer or not.

Re:The cost of forsaking C by akvadrako on Wednesday October 05, 2016 @09:54AM (#12643784)
I am not trying to say it'll work, I'm trying to show that most non-trivial C programs invoke undefined behaviour, according to the spec.

According to my reading an intermediate void pointer allows the pointer casting to stay well defined. However this seems unsafe, even without getting into dereferencing, because implementations are allowed to store omit bits if they assume aligned pointers.

Re:The cost of forsaking C by planteen on Wednesday October 05, 2016 @10:02AM (#12643854)
I'd say my example demonstrates the spec's statement:

"A pointer to an object type may be converted to a pointer to a different object type. If the resulting pointer is not correctly aligned for the referenced type, the behavior is undefined."

The resulting uint32_t pointer in my example is not correctly aligned for the reference type, so undefined behavior (e.g., a trap on RISC) occurs. What's an example of a statement in a "non-trivial" C program that is in common use but you think is undefined?

Re:The cost of forsaking C by akvadrako on Wednesday October 05, 2016 @10:22AM (#12644028)
Okay, now there are two different topics.

(1) I didn't say your example didn't demonstrate a violation, but it misses the point, because it doesn't invoke an intermediate void pointer:

"A pointer to void may be converted to or from a pointer to any object type. A pointer to any object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer."

(2) That was my attempt at coming up with a good example, but it seems, due to the above clause, the casting between incompatible pointers via void * is technically "legal".

Re:The cost of forsaking C by MaulingMonkey on Wednesday October 05, 2016 @09:17AM (#12643517)
To try and give some actual examples:

Undefined:

  int64_t a = 42;
  void* p = &a;
  int32_t* i = p;
  printf("%i", *i);
Implementation defined, as type punning to char is legal (allowing the implementation of memcpy):

  int64_t a = 42;
  void* p = &a;
  char* ch = p;
  printf("%c", *ch);
Exercise left to the reader: Implement a "fast" memcpy (e.g. one that will copy more than 1 byte at a time for large copies, as your standard library implementation likely does) without violating strict aliasing rules.
Re:The cost of forsaking C by Koshkin on Wednesday October 05, 2016 @10:54AM (#12644291)
If you try and hit your finger with a hammer, your subsequent behavior is undefined. Please do not do that.
Re:The cost of forsaking C by akvadrako on Wednesday October 05, 2016 @09:56AM (#12643801)
Where in the standard does it say your first example in undefined?
Re:The cost of forsaking C by MaulingMonkey on Wednesday October 05, 2016 @10:19AM (#12643997)
Since I don't have a copy of the C standard handy, I'll reference this which covers the relevant sections of C++03, C++11, C99, and C11: http://stackoverflow.com/a/7005988/953531 . Quoting the C99 version bellow (§6.5 ¶7):

  An object shall have its stored value accessed only by an lvalue expression that has one of the following types 73) or 88):

  * a type compatible with the effective type of the object,
  * a qualified version of a type compatible with the effective type of the object,
  * a type that is the signed or unsigned type corresponding to the effective type of the object,
  * a type that is the signed or unsigned type corresponding to a qualified version of the effective type of the object,
  * an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union), or
  * a character type.

  73) or 88) The intent of this list is to specify those circumstances in which an object may or may not be aliased.
Bullet 6 is what allows the second sample to have defined behavior. For the first sample, unless I'm seriously mistaken, int32_t isn't considered "a type compatible with" int64_t. Bullet 2 talks of "qualified" versions of types - I believe this is referencing const/volatile qualified types. Bullet 3 apparently allows you to type pun (unsigned int) to (signed int) or vicea versa? Which is an interesting bit of new trivia to me. Bullet 4 is much of the same, bullet 5 requires a nonexistant union, and bullet 6 requests a character type.
Re:The cost of forsaking C by akvadrako on Wednesday October 05, 2016 @10:34AM (#12644123)
Okay, good point - so it's the deferencing step that evokes the clause your mentioned. Apparently, what I learned today, is the cast is fully legal even though it could produce an invalid pointer.

I still wonder if my snippet counts as undefined behavior, since it does dereference an "unknown" void pointer, which may have come from an incompatible object type.

BTW, the latest C1X draft is only at http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

Re:The cost of forsaking C by MaulingMonkey on Wednesday October 05, 2016 @10:47AM (#12644231)
> I still wonder if my snippet counts as undefined behavior, since it does dereference an "unknown" void pointer, which may have come from an incompatible object type.

It counts as potentially undefined behavior - depends on what you pass in. NULL? UB. Pointer-to-uint64_t? UB. Pointer-to-uint32_t? Perfectly defined behavior! ...well, assuming we use ip[0] = 123; instead of ptr[0] = 123;, which won't compile as I've just noticed.

That said, there are some ways to construct pointers which are in and of themselves undefined behavior for merely constructing the pointer:

http://stackoverflow.com/questions/23683029/is-gccs-option-o...

More samples:

  int a[] = { 1, 2, 3 };
  int* b = a+0; // Perfectly defined/legal/normal
  int* c = a+3; // Perfectly defined/legal/normal, just don't deference it (as it points past the end of the array)
  int* d = a+4; // Undefined behavior.  HAIL SATAN!
  int* e = a-1; // Undefined behavior.  Also apparently potentially caused optimization induced breakage in practice.  HAIL GCC!
Re:The cost of forsaking C by koorogi on Wednesday October 05, 2016 @08:44AM (#12643296)
Casting pointers is well defined. What is undefined behavior is to dereference a pointer whose type does not match the pointed-to object.
Re:The cost of forsaking C by akvadrako on Wednesday October 05, 2016 @09:09AM (#12643465)
That's not correct in general; casting pointers is possibly undefined. However, it does seem a made a mistake trying to use void * as an example.
Re:The cost of forsaking C by radmuzom on Wednesday October 05, 2016 @06:37AM (#12642795)
One of the best things about C is it is not upgraded frequently like other languages. So there are no frequent <language> <x.y> released posts here like we see for other languages.
Re:The cost of forsaking C by creshal on Wednesday October 05, 2016 @06:43AM (#12642815)
On the downside, when it does get updated, compilers take ages to implement the new features, and in the meantime make up busywork like "let's break OS kernels or crypto code to get faster in some random benchmark nobody cares about!"
Re:The cost of forsaking C by dom0 on Wednesday October 05, 2016 @07:58AM (#12643078)
Don't need C updates for that, a GCC upgrade is quite sufficient! :(
Re:The cost of forsaking C by joosters on Wednesday October 05, 2016 @08:49AM (#12643329)
gcc is generally used as a testing ground for new C/C++ features. So in most cases, the compiler supports new features before they are 'officially released' into the language.

It's the complete opposite of waiting for a feature to appear in the compiler.

Re:The cost of forsaking C by creshal on Wednesday October 05, 2016 @09:42AM (#12643683)
GCC didn't get sort-of-complete C11 features until 4.9 (2014) and still omits (largely useless) optional features.
Re:The cost of forsaking C by bkjsbkjdnf on Wednesday October 05, 2016 @10:16AM (#12643963)
> You know what you get with C and it just works as you expect always.

Every language works just as you expect if you have the right expectations.

Re:The cost of forsaking C by henrik_w on Wednesday October 05, 2016 @06:58AM (#12642869)
"minimal syntactic sugar" made me think of this quote:

"C is memory with syntactic sugar." Dennis Kubes

Re:The cost of forsaking C by vilya on Wednesday October 05, 2016 @08:24AM (#12643170)
> Want to know where every last cycle goes and explicitly control everything? C

So... you compile with optimisation switched off?

Re:The cost of forsaking C by lightcatcher on Wednesday October 05, 2016 @10:22AM (#12644027)
There's something to be said to be familiar enough with the optimization that you can predict assembly that is not a direct translation of what you're writing.

For instance, when writing a scalar-processing loop over a fixed length array with no dependency between iterations you can reasonably expect the compiler to convert to SIMD instructions and do some unrolling. It's not too difficult to check the binary that this happened, and if it doesn't happen you just write it yourself with intrinsics.

I often think of C + compiler's optimization passes as a "scripting language for assembly".

Re:The cost of forsaking C by Nursie on Wednesday October 05, 2016 @09:37AM (#12643636)
In some cases you may wish to, yes. Particularly where it comes to things like explicitly zeroing memory before freeing it, something that has recently been addrezsed with memset_s
Re:The cost of forsaking C by vilya on Wednesday October 05, 2016 @06:30PM (#12648525)
That's exactly my point: when the compiler can decide not to do something you told it to you don't have full explicit control over everything. That's not a bad thing though - the compiler usually makes good decisions on your behalf. Usually.
Re:The cost of forsaking C by KKKKkkkk1 on Wednesday October 05, 2016 @09:30AM (#12643592)
I love C with all my heart, but minimal in the syntactic sugar department it ain't. Other languages of its day like Fortran or Pascal would not let you write an atrocity like

  while (*++targ = *++src)
    ;
Re:The cost of forsaking C by 3chelon on Wednesday October 05, 2016 @10:02AM (#12643848)
Clear and concise, and a thing of beauty!

Unless the data is user-generated, in which case you might have a security issue on your hands... :)

Re:The cost of forsaking C by Nursie on Wednesday October 05, 2016 @09:33AM (#12643610)
Well, that's up to you whether you write that way or not.

Kinda like with everything else related to C!

Re:The cost of forsaking C by imagist on Wednesday October 05, 2016 @09:51AM (#12643760)
> Well, that's up to you whether you write that way or not.

The problem is, it's also up to the programmers who worked on my codebase before I did. I would never write that atrocity, but I've come across that atrocity quite a few times in code I needed to modify.

Re:The cost of forsaking C by Nursie on Wednesday October 05, 2016 @10:06AM (#12643882)
I'll.never claim there aren't a ton of terrible coders out there. They exist in all languages, but perhapd C gives them the tools to be really, extra awful..
Re:The cost of forsaking C by imagist on Wednesday October 05, 2016 @01:53PM (#12646120)
It also doesn't give you very good tools for refactoring to clean up the awfulness. Unit testing tools and the type system in C are such that it's fairly difficult to ensure that your refactor hasn't broken anything.
Re:The cost of forsaking C by jjaredsimpson on Wednesday October 05, 2016 @10:01AM (#12643844)
Not really an atrocity. More like an idiom.
Re:The cost of forsaking C by jstimpfle on Wednesday October 05, 2016 @09:37AM (#12643634)
perfectly readable :)

(but usually generates compiler warning without an additional set of parentheses)

Re:The cost of forsaking C by solidsnack9000 on Wednesday October 05, 2016 @01:37PM (#12645954)
I think the strongest thing in C's favor is that it is an extremely simple language, so it's easy to port and easy to write (semi-broken) compilers for. A language like C++, D or Rust, being more complicated, can take longer to provide ports for.
Re:The cost of forsaking C by Manishearth on Wednesday October 05, 2016 @10:54PM (#12649888)
All three of those languages have at least one compiler with an llvm backend, so writing ports should be as hard as C. Perhaps easier, since you don't actually have to write a parser for anything, just an IR->asm pass.
Re:The cost of forsaking C by tonyjstark on Wednesday October 05, 2016 @10:17AM (#12643983)
up to 'trivially import...' I thought about FORTH, not that I have any experience with it besides some tutorials.