Live data from Hacker News

So you think you know C? (2016)

wordsandbuttons.online

341–344 of 344 posts

Re: So you think you know C? (2016)

#341
post #212

Earlier quoted context omitted.

1) This made me curious. Are any of the compilers in real use nondeterministic? 2) Probably that's not needed? A normal optimizing compiler just inlines the function somewhere new — and boom? Then again, can that really happen with practical contemporary compilers and this exact statement?

Most compilers are nondeterministic in small ways. For example, it's common to use hash tables that are keyed by pointer address and then iterate over the entries in storage order, so the order in which certain things are emitted will change from run to run. This is why "deterministic builds" are such a big deal, and not just an obvious thing that you get for free. I don't know what the chances are that such a thing…

Register allocation can be quite tricky, and sometimes it can only explore a small part of the problem space, so if you don't start the algorithm with exactly the same seed you might end up with significantly different code in certain functions.

Re: So you think you know C? (2016)

#342
post #301

Earlier quoted context omitted.

Which only works if the sequences align perfectly. Handling misaligned collections is more awkward with functional constructs. Functional graph programming is also still a bit of an open problem. There are awkward scenarios in both cases.

Ah, I see what you mean. Yeah, that’s always awkward Not sure how you deal with that with for loops either. Increment the iteration var in the body of the loop? (Seems scary to me, but like I said, I’ve got terrible intuition with them)

For something like iterators:

    var ie1 = foo.GetEnumerator();
    var ie2 = bar.GetEnumerator();

    while(true)
    {
        var has1 = ie1.MoveNext();
        var has2 = ie2.MoveNext();
        if (!has1 && !has2)
            break;
        if (has1)
            // do something with ie1.Current
        if (has2)
            // do something with ie2.Current
    }

Re: So you think you know C? (2016)

#343

Earlier quoted context omitted.

I'm well aware of what undefined behavior is. I still know it's undefined behavior and can read my compiler manual to answer the question of how the code behaves. "I don't know" is simply wrong.

> and can read my compiler manual to answer the question of how the code behaves. Which is both not true (because the compiler manual usually won't define undefined behaviour) and irrelevant (because the questions were about C, not about a compiler).

In the example I choose (#2) most compilers totally specify the behavior. And the question was (right from the article) "what the return value would be?" In order for a function to return, it must be run. In order for a function to be run, it must be compiled. In order for a function to be compiled, there must be a compiler (or interpreter, I suppose).

You're being pedantic about something silly, but you're also wrong in your pedantry.

Re: So you think you know C? (2016)

#344

Having written a conforming C compiler, at one point I knew everything there was to know about C (I forget details now and then, or confusing them with C++ and D). But knowing every engineering detail is not the same thing as knowing how to program in C effectively. It's like being the engineer who designs a Grand Prix car. It does not mean you can drive it faster around the track than anyone else. Not even close. Fo…

> at one point I knew everything there was to know about C

after taking the test, wouldn't this be:

at one point I knew everything there was to know about (my implementation of) C

also: one time long ago I tried to use the c-preprocessor to preprocess a data file. ha ha ha ha ha. (conclusion: don't do that)

Post reply on HN