News for hackers. Stuff that matters.
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by junk_disposal on Monday February 13, 2017 @09:32PM (#13640718)
Honestly, Optimizing compilers will kill C.

It killed the one thing C was good at - simplicity (you know exactly what happens where, note I'm not saying speed, as C++ can be quite a bit faster than C).

Now, due to language lawyering, you can't just know C and your CPU, you have to know your compiler (and every iteration of it!). And if you slip somewhere, your security checks blow up (http://blog.regehr.org/archives/970 https://bugs.chromium.org/p/nativeclient/issues/detail?id=24...) .

Re:I Do Not Know C: Short quiz on undefined behavior (2015) by msbarnett on Monday February 13, 2017 @09:45PM (#13640760)
> Now, due to language lawyering, you can't just know C and your CPU, you have to know your compiler (and every iteration of it!).

This mythical time never existed. You always had to know your compiler -- C simply isn't well specified enough that you can accurately predict the meaning of many constructs without reference to the implementation you're using.

It used to, if anything, be much much worse, with different compilers on different platforms behaving drastically different.

Re:I Do Not Know C: Short quiz on undefined behavior (2015) by vyodaiken on Monday February 13, 2017 @09:51PM (#13640788)
This is not really correct. The kinds of implementation dependencies usually encountered reflected processor architecture. The C standards committee and compiler community have created a situation in which different levels of "optimization" can change the logical behavior of the code! Truly a ridiculous state of affairs. The standards committee has some mysterious idea I suppose, but the compiler writers who want to do program transformation should work on mathematica or prolog, not C.
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by prodigal_erik on Monday February 13, 2017 @10:41PM (#13640971)
Compiler writers have to use program transformation to do well on benchmarks. Developers who don't prioritize benchmarks probably don't use C, and if they do they really shouldn't, because sacrificing correctness for speed is the only thing C is good for these days.
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by umanwizard on Tuesday February 14, 2017 @12:51AM (#13641492)
Speed isn't the only reason to use C. I often use C not because it's fast, but because C is by far the simplest mainstream programming language. All these UB warts notwithstanding, no language's interface comes as close as C's to a basic, no-frills register machine.
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by red75prime on Tuesday February 14, 2017 @02:02AM (#13641771)
You don't need speed, but you want to write in a language, which is closest to assembly? Hmm. Interesting view on what is simple.
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by umanwizard on Tuesday February 14, 2017 @03:06AM (#13642046)
Maybe we mean different things by the word "simple". What language do you think is simpler than C?
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by adrianN on Tuesday February 14, 2017 @04:35AM (#13642370)
Scheme, ML, Java, Lua...
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by umanwizard on Thursday February 16, 2017 @05:54PM (#13664375)
Yeah, we must have different definitions of simplicity, as I expected.

Just off the top of my head, Java has the following complexities that C lacks: exceptions, garbage collection, class inheritance, generics, and a very large standard library.

What definition of simplicity are you using when you say Java is simpler than C?

Re:I Do Not Know C: Short quiz on undefined behavior (2015) by junk_disposal on Monday February 13, 2017 @11:27PM (#13641143)
In reality, that's why I think that neither Go nor Rust will ever replace C (Maybe C++, Java or Python), because nothing can replace C.

C worked in the 70s, when a naive compiler + asm would work perfectly.

Re:I Do Not Know C: Short quiz on undefined behavior (2015) by Hydraulix989 on Tuesday February 14, 2017 @01:40AM (#13641683)
Why though? At the end of the day, both are pretty C-like.
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by vyodaiken on Tuesday February 14, 2017 @08:56AM (#13643486)
Oh please.
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by dbaupp on Monday February 13, 2017 @09:56PM (#13640807)
Optimisers are what made C what it is: they convert the idealised PDP-11 assembly into something efficient on modern computers, and speed is something C programmers care about.
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by ArkyBeagle on Monday February 13, 2017 @10:39PM (#13640963)
In the large, no, they don't care about the 90-95% of the code base that's not performance critical. And these days, the stuff that is critical will be #ifdef and asm(...) stew.

I can't tell you how many projects I have been on where disabling optimization made no measurable difference in performance.

This being said, I cannot speak for game devs nor video device driver developers.

Re:I Do Not Know C: Short quiz on undefined behavior (2015) by E6300 on Monday February 13, 2017 @11:11PM (#13641071)
I have to say, I have never encountered a program where compiling without optimizations made no difference. If you have seen that, then I would agree that C was a very, very poor choice for that particular domain.
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by ArkyBeagle on Wednesday February 15, 2017 @02:23AM (#13650334)
It made no measurable difference. The acceptance criteria for the system were not materially affected. Since the optimization did not improve the performance by that, it was generally set one way ( mostly off ) and let that way.

Teams I'm on have written some tight - but readable -code, too. Well-architected, low-latency, low-jitter.

Re:I Do Not Know C: Short quiz on undefined behavior (2015) by pjmlp on Tuesday February 14, 2017 @02:16AM (#13641846)
Business applications, as it was common in the 90's.

Witting them in C or VB made no difference for the guys sitting at the desk.

Re:I Do Not Know C: Short quiz on undefined behavior (2015) by ArkyBeagle on Wednesday February 15, 2017 @02:26AM (#13650350)
This ranged from networking equipment to phone switches to equipment control. Most of it was bare metal.

I've never written a business application in my life.

Re:I Do Not Know C: Short quiz on undefined behavior (2015) by adrianN on Tuesday February 14, 2017 @04:39AM (#13642386)
You can try an experiment and build an application like Firefox from source with disabled optimizations. I bet you'll notice a massive difference.

Even more important are things that run in datacenters on thousands and thousands of machines. Even if you suppose that optimizations make only a minuscule difference on the scale of today's infrastructure 5% fewer machines can save huge amounts of electricity.

Re:I Do Not Know C: Short quiz on undefined behavior (2015) by ArkyBeagle on Wednesday February 15, 2017 @02:28AM (#13650358)
Why would I want to build Firefox from source? I don't build things that run on thousands of machines. Last thing I ran any code on had a 2500 HP diesel; the electronics were in the noise.
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by tacostakohashi on Monday February 13, 2017 @10:13PM (#13640870)
If you do know your compiler and your CPU (singular), you're probably not really programming C.

Conversely, if you maintain software that compiles on a bunch of compilers, operating systems and architectures (particularly little endian + big endian, 32 bit + 64 bit), then it's probably written in something rather like C. A lot of people do this.

Re:I Do Not Know C: Short quiz on undefined behavior (2015) by ArkyBeagle on Monday February 13, 2017 @10:35PM (#13640950)
Just use the parts that work unambiguously. It's a surprisingly small subset of the language.
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by baby on Tuesday February 14, 2017 @10:13AM (#13643963)
undefined behavior has always been undefined behavior. Optimizing the compiler doesn't change that fact.