Slashdot Mirror


Linus Rants About C Programming Semantics (iu.edu)

jones_supa writes: "Christ people. This is just sh*t," begins Linus Torvalds in his message on the Linux Kernel Mailing List. Torvalds is grumpy because some new code added to the IPv6 subsystem has created conflicts. "The conflict I get is due to stupid new gcc header file crap," he writes. "But what makes me upset is that the crap is for completely bogus reasons." The new improved code uses fancy stuff that wants magical built-in compiler support and has silly wrapper functions for when it doesn't exist. Linus provides an alternative that contains a single and understandable conditional, which looks cleaner and generates better code.

11 of 576 comments (clear)

  1. Re: Not saying I disagree with Torvalds by Anonymous Coward · · Score: 5, Informative

    It's literally just a few rants out of thousands of friendly messages per year - and Linus only rants if crappy code comes from someone who is trusted by Linus (such as the networking maintainer here) and who should really know better.

  2. Incorrect headline by Dog-Cow · · Score: 4, Informative

    Not that this will surprise much of anyone, but the headline is wrong. Linus did not rant about C programming semantics. He ranted about a specific C function and the style used to perform a sanity check.

  3. Re:Not the case. by DrXym · · Score: 5, Informative

    Goto is a perfectly valid instruction providing you know when to use it. The typical use would be to jump into some teardown code at the bottom of a function or to escape out of some nested loop. Either way provdes more succinct and involves less code than the alternative. I assume every single kernel developer is capable of knowing when best to use it and they wouldn't have to worry about issues with c++ constructors either.

  4. Re:Linus is right. by Polizei · · Score: 4, Informative

    Not to state the obvious, but here's the definition of `overflow_ubus`

    static inline bool overflow_usub(unsigned int a, unsigned int b,
    unsigned int *res)
    {
    *res = a - b;
    return *res > a ? true : false;
    }


    So the 2 conditionals from the patch are completely idiotic and wrong.
    `overflow_ubus` not only makes an unnecessary assignment to `mtu`, but does a check after that assignment, and then you need another check for it outside of `overflow_ubus`.

    In general, the proposed patch conditionals could be rewritten as

    unsigned int oldmtu = mtu;
    mtu -= hlen + sizeof(struct frag_hdr);
    if (mtu > oldmtu || mtu <= 7)
    goto fail_toobig;


    Now that's ugly!

  5. Re:reality by ledow · · Score: 3, Informative

    The new syntax only works on certain versions of the GNU compilers. It's also more convoluted, just as easy to get wrong (i.e. the guy himself admits there's a possibility of the same kinds of mistakes as without it), non-standard, and harder to read - especially if you are unfamiliar with a GNU-only syntax.

    Read the rant, then look at the code.

  6. Re:Linus rants about EVERYTHING by mysidia · · Score: 3, Informative

    ...except systemd, which will soon become linuxd.

    He already ranted about SystemD code.

    "Key, [sic] I'm f*cking tired of the fact that you don't fix problems in the code *you* write, so that the kernel then has to work around the problems you cause," Torvalds fumed
    ....
    ....

    For his part, Sievers appeared unmoved by Torvalds' outburst. After posting a tongue-in-cheek status update to Google+, he reposted a missive by Lennart Poettering explaining that the systemd developers would address the issue with a software patch.

  7. Re:Is there a use for overflow_usub? by Anonymous Coward · · Score: 3, Informative

    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0103r0.html

    I guess the compiler developers and the IETC are all just idiots.

    We use these functions in HFT all the time. Too bad it's too "complicated" for kernel developers to understand...

  8. Re:I never understood why by SQLGuru · · Score: 1, Informative

    If they used it like a headline, it would be fine. But they don't. They use it as the location for the beginning of their first sentence.

    Subject: Anonymous Cowards don't know how to
    Body: use the Internet.

    Newspapers don't write their articles that way......they write them like this --

    Subject: Anonymous Cowards don't know how to do this....
    Body: Anonymous Cowards are apparently clueless Trolls because they don't know how to use the Internet. They think that Subjects are where you start the first sentence of your article and then you just continue the sentence in the body as if that is just an inconvenience to spewing their diatribe.

    See.....a real Subject (akin to a headline) that conveys an idea of what the body will discuss but it's followed by a full concept that can also stand alone if the subject is hard to read (for instance on a site like Slashdot where it gets lost in the green bar).

  9. Re:goto is perfectly fine here. by coats · · Score: 3, Informative
    Donald Knuth agrees with you, by the way.

    Part of the reason is this: while it's provable that you can use ifs and whiles to eliminate all gotos, the proof also demonstrates that code-length may grow exponentially in the number of gotos eliminated.

    --
    "My opinions are my own, and I've got *lots* of them!"
  10. Re: Linus rants about EVERYTHING by chaboud · · Score: 4, Informative

    I have to agree. I was ready to read a melodramatic rant over slightly new semantics, but I instead found a completely justified and reasonable criticism of horribly unreadable (and kind of broken) code. With some extra swearing thrown in for Linusness.

    Remember, coders, if you're doing anything with code that will be used by others or reused by you, readability is crucial. I'm not talking about comments unless the code itself needs to be less readable (e.g. Performance in a hot spot). I mean the code itself.

    And, by code that others may use or you may re-use, I mean all code.

  11. Re: When create the most used operating system by rickb928 · · Score: 3, Informative

    Do or not do. There is no criticize.

    --
    deleting the extra space after periods so i can stay relevant, yeah.