
Linus Torvalds on aliasing - r4um
http://www.yodaiken.com/2018/06/07/torvalds-on-aliasing/
======
mosselman
I would go out of my way to avoid people who communicate like this with me.
People put time and energy in making software better, at least in their own
eyes, for others and then they get textually abused like this by someone who
has his fame to protect himself with.

He also does no service to his own arguments by peppering them with childish
swearing because things like "So standards are not some kind of holy book that
has to be revered. Standards too need to be questioned." can't be said enough
to some people in the industry.

If his reply were written with more tact and less swearing it would be a lot
more powerful. We as an industry should demand this of each other, but also of
our 'celebrity' colleagues.

~~~
ralfn
When it comes to being oversensitive needy little things there is no true
Scottsman.

As a northern European I find it not only comfortable that Linus runs Linux,
but I would be less comfortable if it was another American smile in face
pretend to be your friend but be shady as fuck attitude that you guys seem to
confuse for 'professionalism'.

So let's chalk this to cultural differences. We wouldn't hire someone like you
and you wouldn't hire someone like him.

~~~
kristianc
> As a northern European I find it not only comfortable that Linus runs Linux,
> but I would be less comfortable if it was another American smile in face
> pretend to be your friend but be shady as fuck attitude that you guys seem
> to confuse for 'professionalism'.

This is a false dichotomy.

Most of what Linus says would run foul of HN's guidelines - which I'll
paraphrase here as "don't call someone an asshole before making your real
point", but that doesn't mean that everyone on HN is a 'smile in face pretend
to be your friend but be shady as fuck'.

~~~
ralfn
When somebody speaks their mind, everybody around them knows where they stand.

I doubt there is difference between about how often people resent other people
around the world. But I do consider it more humane if resentment isn't hidden
under the surface. It's easier to trust Linus than a tactfull politician. That
should make us all think.

~~~
mannykannot
One circumstance where insults might be justified is where one party has
ignored valid objections to his position.

I mention this here because kristianic made the valid point that you have set
up a false dichotomy, and you replied with a statement that keeps it going. Is
the habit of not paying attention to the actual issues also part of your
superior Northern European culture, and, in fact, is it perhaps a reason why
insults are apparently such an important part of it?

~~~
mannykannot
I see someone chose to down-vote without commenting - presumably not one of
those self-described straight-talking Northern Europeans?

------
pubby
To me, this rant seems more directed at C standards people than the guy he
sent it to. That doesn't excuse his vitriol, but I hope people will read
between the lines.

Sometimes people forget that C was created for writing operating systems. They
get in their mind that C is all about high-performance, and that making it
competitive with FORTRAN is the way to go. I understand that, but it's not
what C was created for. If the world's most famous C programmer and OS guru
wants to have strong opinions on the direction of the language, I say allow
it.

~~~
simias
>C was created for writing operating systems

That doesn't properly justify C's minefield around aliasing and type punning
in general. It's UB galore. Thing is, whenever you're writing low level code
that's tied to hardware in my experience you very often end up having to pun
your types to match hardware constraints, and at this point the C standard
basically says "lol good luck with that bro".

I'm not a programming language expert but IMO at the very least C should make
reading from a different union member than was last written to "implementation
defined" instead of UB (with suitable constraints if the sizes of the members
differ I suppose). In effect that's mostly how compilers deal with that
anyway.

So I agree with Linus that the C standard is really unhelpful in these
situation, although his childish anger is unnecessary and counter-productive.

~~~
pubby
>at the very least C should make reading from a different union member than
was last written to "implementation defined"

That's how it is :) The standard even describes union behavior as "type
punning".

I don't know if C++ allows it though.

~~~
maccard
Don’t think c++ allows it. Last time I checked, if you use any modern
compiler, and do a memcpy, and check the assembly, it does the right thing.

~~~
saagarjha
Yes, that's the "approved" way of doing type punning. Any decent compiler will
immediately optimize that down to nothing.

------
netule
Notice that after his rant, he still tested the code, and merged it:
[https://lkml.org/lkml/2018/6/5/774](https://lkml.org/lkml/2018/6/5/774)

~~~
sleepychu
Did he get some follow up from the author of the changes?

~~~
proaralyst
I think that's here:
[https://lkml.org/lkml/2018/6/6/88](https://lkml.org/lkml/2018/6/6/88)

------
caf
It's important to bear in mind that Linux isn't written in standard C - it's
written in a dialect of C implemented by recent-ish versions of GCC (there is
a particular minimum GCC version supported), with certain compiler switches.

There's nothing wrong with this - it's an important enough project to be able
to make those kinds of demands.

~~~
stefan_
Android kernels are built with Clang. So really it's just missing support for
MSVC, for obvious reasons.

~~~
berti
For now, at least [1][2]. See the rest of that thread.. llvm guys really don't
want asm goto, and kernel really wants it.

[1] [https://lkml.org/lkml/2018/2/14/724](https://lkml.org/lkml/2018/2/14/724)
[2] [https://lkml.org/lkml/2018/2/14/157](https://lkml.org/lkml/2018/2/14/157)

~~~
stefan_
Well, yeah, that's what the other commentators here misunderstand. Sure the
kernel is C, but a non-optional part is assembly in various forms that
obviously is not standardized between compilers. So it takes effort to support
kernel building. Google paid up and made that happen.

------
nabla9
Swearing and profanity is an art form. Habitual swearing is bad style just
like habitual use of smileys and LOL's.

If Linus would habitually curse in the kernel list, it would have no emphasis
effect and it would be a really bad style. Linus using cursing in a rant
equals [for wider distribution] and it works perfectly. I can't remember a
single discussion linked to HN that didn't start from cursing. It provided the
opportunity for people to be offended. For technical people it's a challenge
(like a glove slap).

Example:

* his opinion about hardening: [https://lkml.org/lkml/2017/11/21/356](https://lkml.org/lkml/2017/11/21/356)

* previous message that collected the attention: "Those security people are f*cking morons." [https://lkml.org/lkml/2017/11/17/767](https://lkml.org/lkml/2017/11/17/767)

------
sandGorgon
> _The fact is that gcc documents type punning through unions as the "right
> way". You may disagree with that, but putting some theoretical standards
> language over the explicit and long-time documentation of the main compiler
> we use is pure and utter bullshit._

this was the whole point of the rant.

------
CBLT
Previous discussion:
[https://news.ycombinator.com/item?id=17242103](https://news.ycombinator.com/item?id=17242103)

------
Benjamin_Dobell
Linus has done some (okay, lots of) wonderful stuff. However, his attitude
here is pretty extreme. Being incredibly rude, then proceeding to merge said
pull request. If Linus is willing to merge the PR, then it can't be _that_
bad. Surely there was a more tactful way to approach this, even for Linus.

~~~
iliaznk
Why should he NOT being rude? Has anyone ever answered him in the same way?
Has anyone ever publicly explained him that while being a sociopathic nerd he
still must comply to some basic rules of conduct like we all do. The guy is
willingly putting on and supporting the public image he's got and, obviously,
loving it. I know, that he's smart and what not, but why should it be an
excuse for being an asshole? I just realised that he reminds me of Taleb.

~~~
coldtea
> _Why should he NOT being rude? Has anyone ever answered him in the same
> way?_

Several, but no one that mattered enough with respect to Linux for his opinion
to matter in return.

His OS, his rules. Others can always fork it if they have an issue with that.

It seems to have worked fine as a gatekeeping technique for the last 25+
years, even if it hurts some feelings. Linus goes for an in-the-trenches,
rough camaraderie, approach, rather than a "professional soft spoken cubicle
workers" approach.

~~~
hfdgiutdryg
_Linus goes for an in-the-trenches, rough camaraderie, approach_

He's an outright toxic and abusive person. Characterizing a lack of toxic,
abusive behavior as "professional soft spoken cubicle workers approach" is
disingenuous.

~~~
coldtea
Well, if he was "outright toxic", then he would have had negative effects on
the kernel development. Which I don't see happening.

So what people mean with that is not that he actually has a toxic effect, but
that they dislike his tone.

~~~
JakeTyo
This is a malformed argument.

Having a 'toxic' personality does not mean he will produce bad code. Two
completely different things.

~~~
coldtea
I didn't say that "toxic = he'll produce bad code".

I said that the claim of those saying he's language is toxic is that his
language poisons the Linux kernel community development.

And yet, I counter-argue, I see it doing just fine, and going from strength to
strength, over the last 25 years. If there's any toxicity effect, I wont see
it affecting much, if anything.

I could accept that it might have led some people who could have otherwise
contributed away. But I don't see this having any substantial effect on
Linux's development.

Perhaps it's even beneficial (since the outcome and results from Linux's
development team is better than from any other Unix-like OSS OS, with their
supposedly not toxic leaders).

If that freedom of language is all it takes to keep Linus happy, and
stewarding the project as well as he has done all these decades, then so be
it...

------
henearkr
Am I the only one understanding that finding funny ways to rant is one of
Linus' favourites hobbies? And so that he is not doing that to hurt people,
but to entertain? He makes that particularly clear by attending gatherings
about pirates' language, etc. Stop try to change him, because without this
humorous spice his release notes would be way too boring.

------
muxator
Come on, this is wonderfully blunt!

> In fact, I'll take real toilet paper over standards any day, because at
> least that way I won't have splinters and ink up my arse.

~~~
johnday
You can be blunt without being rude. Most of the post is just rudeness.

~~~
raverbashing
Rudeness is a cultural variable.

An Englishman saying "that's interesting" can be more rude than someone else
saying "get lost"

------
watwut
Linus Torvals says something technical and full of insights while keeping
control over emotions - crickets nobody cares.

Linus Torvals adds some insults into the above or simple does not even
attempts to keep control over his emotional side - half people jump up and
down happy like a fourteen years old. Wow, look, he used insult! The other
half suddenly turns into prude "I never swear nor insult anyone" Victorian
aristocrats - despite having tweet feeds full of, and I am quoting here,
"fucks".

------
2bitencryption
first thing I do when I see a Linus email: ctrl+f "braindamage".

never disappoints.

~~~
ddtaylor
I search for "garbage" or "trash"

------
piinbinary
Google cache:
[http://webcache.googleusercontent.com/search?q=cache%3Ahttp%...](http://webcache.googleusercontent.com/search?q=cache%3Ahttp%3A%2F%2Fwww.yodaiken.com%2F2018%2F06%2F07%2Ftorvalds-
on-
aliasing%2F&oq=cache%3Ahttp%3A%2F%2Fwww.yodaiken.com%2F2018%2F06%2F07%2Ftorvalds-
on-aliasing%2F&aqs=chrome..69i57j69i58.1183j1j7&sourceid=chrome&ie=UTF-8)

------
drdrey
Can someone ELI5 what the issue is with type punning and union aliasing?

~~~
ufo
Suppose you want to look at the bits of a floating point number, as though it
were an integer. The type punning way to do that would be to access a double
in memory through an integer pointer:

    
    
        double d = 3.14;
        int64_t *p = (int64_t *) &d; // !!!
        int64_t n = *p;
    

The union aliasing way would be to makeset the double field in a union and
read the integer field back:

    
    
        typedef union {
            double d;
            int64_t n;
        } int_or_double;
    
        int_or_double u;
        u.d = 3.14
        int64_t n = u.n
    

According to the standard, the union aliasing approach is allowed, but the
type punning one is undefined behavior.

\---------

The standard team decided to forbid type punning to allow compilers to
implement more optimizations. They still allow union aliasing because they
felt there should still be a way to do low-level type casts if for those that
absolutely want to.

~~~
blorsh
No, type punning via unions is a gcc extension.

The standard only allows reading a value as the type it was written with or as
char, and an access as char is only good for copying. If a char access used
different bit order, that would be OK according to the standard because you
couldn't tell unless you violated the standard.

It seems every compiler will tolerate a memcpy for type punning, even though
this isn't required.

~~~
Athas
Does this mean that memcpy() is really more of a language construct than a
library function, since it cannot be implemented correctly in fully defined
standard C?

~~~
adrianN
Yes. Check here for a discussion:
[https://blog.regehr.org/archives/959](https://blog.regehr.org/archives/959)

------
xenadu02
Make this construct legal behavior without making it 10x slower than clang/gcc
are today:

    
    
      void wat(uint16_t *x, uint16_t *y) {
        *x = *y;
      }
    
      uint64_t a[100] = { 0 };
      wat((uint16_t *)&a[0], (uint16_t *)(((char *)&a[0]) + 1));
    
    

When you think you've figured that one out, try this one:

    
    
      uint16_t heh = 0xFFFF;
      extern uint16_t doesAnything(uint16_t *, uint16_t *);
      void wat(uint16_t *x, uint16_t *y) {
        *x = *y + doesAnything(&heh, y);
      }
    
      uint64_t a[2] = { 0 };
      wat((uint16_t *)&a[0], (uint16_t *)(((char *)&a[0]) + 1));

~~~
AstralStorm
Missing the point. Linus was talking about _union aliasing_.

------
Forge36
How well do they know each other? Is it possible Rafael (the contributor)
wasn't as upset by this as an outside observer?

Linus is obviously being harsh, his words are also preserved publicly as a
part of the contribution. He's arguing against the logical fallacy. Had he not
swore: would we discuss this?

------
matt4077
I'm in no way offended by Torvalds' typical expletive-laden rants. But they do
strike me as a terrible way to communicate.

These outbursts seem to happen every few weeks, and have long seized to
surprise. IF anything actually bad ever comes up, he has no further escalation
available to raise awareness.

It also reminds me of these choleric bosses screaming at someone every day:
it's almost always a sign that they're insecure, sociopaths, or can't handle
their responsibilities.

~~~
beaconstudios
This is the actual reason his manner of communication is poor - swearing and
generally blunt language like this should be reserved for shaking people into
action, whether it's due to their otherwise ambivalent attitude or the
severity of the situation. By making a big fuss for every moderate concern he
has, he leaves few options open for when the situation demands that people
spring into action.

------
minipci1321
I never take these "what Linus just said" posts for their face value. To me,
it sounds as a half-staged, half-talking-to-buddies, mostly good-natured
grudges, for some reason I cannot explain. (That said, I am not contributing
to kernel, my very first post to some kernel list got a much worse response
for no good reason (not from Linus). It was enough.)

But I work in customer support of highly technical products, and I visit
various companies very often. By now, I can figure this type of persons from
the first communication -- not the ones who does it the way Linus does it (see
above), but the real a&^%$%^$les -- owning some inner knowledge unavailable to
others, just because they happened to be here from the bigbang and haven't
evolved since. Boy, is this "rough but just and truthful" attitude counter-
productive to projects! I haven't seen any exception to that yet.

------
solotronics
I never really understood why people complain about Linus personality. If you
don't like it go somewhere else nobody is forcing you to code for Linux.

Fork it and make your own.

~~~
yellowapple
> Fork it and make your own

Even Google couldn't pull that off with Android.

~~~
iliaznk
Another question is would Linux become what it's become if everyone would
really have just forked it?

~~~
Brian_K_White
Another question is would Linux become what it's become if only nice polite
guys were allowed to code it?

~~~
iliaznk
That's irrelevant, nobody's talking about allowing or not allowing to
participate, but accepting help while insulting the helpers, seems disgusting
to me and I really find it weird that some people readily accept that while
demanding respect and politeness in other situations. Double standards –
that's what it is.

~~~
Grollicus
I don't see him here "insulting the helpers". He's saying the argument for
this change is bad, he's saying a bunch of things in the C standard are bad,
but there's nothing personal there.

------
thecompilr
Can't say much changed over the years
[https://lkml.org/lkml/2003/2/26/158](https://lkml.org/lkml/2003/2/26/158)

------
ufo
I work with a codebase that implements a sort of OO inheritance in C. It looks
like this:

    
    
        #define BASE_FIELDS int a; int b; int c;
    
        struct Base {
            BASE_FIELDS
        };
    
        struct Derived1 {
            BASE_FIELDS
            int d; int e;
        };
    
        struct Derived2 {
            BASE_FIELDS
            int f; int g;
        };
    

Then, it has lots of code that accesses Derived objects through a `Base*`,
with ->a and so on.

Is this against the standard C aliasing rules? If so, how would this need to
be rewritten to conform to the standard?

~~~
comex
It is against the rules. To fix that, you'd need to put a field of type
'struct Base' in the derived struct(s) rather than just copying its fields.

edit: If you want to keep the existing syntax and can use GCC extensions, it
should be legal to use an unnamed union:

    
    
        struct Derived1 {
            union {
                struct Base base;
                struct {
                    int a; int b; int c;
                };
            };
            int d; int e;
        };
    

edit2: or, with -fms-extensions, just

    
    
        struct Derived1 {
            struct Base;
            int d; int e;
        };

~~~
ufo
Putting a field of type 'struct Base' adds extra padding in my case,
unfortunately.

~~~
loa-in-backup
I believe there is a way to disable field alignment on a case-by-case basis. I
could be wrong, though.

~~~
comex
Yes, there's the GCC extension __attribute__((packed)), or #pragma pack, an
extension supported by both GCC-style compilers and MSVC.

------
jhoechtl
> In fact, I'll take real toilet paper over standards any day, because at
> least that way I won't have splinters and ink up my arse.

So Linus, made my day!

------
badpenny
Kind of sad that a person as intelligent as him can get to his age and still
not realise that talking to people that way is at best highly ineffective and
at worst will make them actively hostile towards you. That's not to mention
rude and mean-spirited.

~~~
zkomp
I just don't see it. He is frustrated with _the standard_ being wrong, no
personal insult or anything.

------
okket
Déjà vu (or "dupe")

[https://news.ycombinator.com/item?id=17242103](https://news.ycombinator.com/item?id=17242103)

------
alexeiz
> In fact, I'll take real toilet paper over standards any day

You can print the Standard on the real toilet paper and have the best of both
worlds. Read before wipe!

------
squarefoot
I also wouldn't like being addressed like that and if I was I probably would
quit working with him, but he gave a very clear explanation why he became more
direct in dealing with people. And unless one lives that same experience in
his own shoes it's not easy to make an opinion.

------
jeisc
It is people that matter; all software is only made to serve people. One
person can be the holder of a solution to an important problem, so that person
must be able to express his ideas even when they go against the common wisdom.

------
pajop
plot twist: Linus actually merged it! :)

[https://lkml.org/lkml/2018/6/5/774](https://lkml.org/lkml/2018/6/5/774)

------
mistermann
I sometimes wonder what the world of computing, or even the world in general,
would look like today if Linus Torvalds hadn't existed, or happened to have
not gotten into computers.

~~~
ankurdhama
Someone else would have.

~~~
loeg
(BSD :-))

~~~
bcaa7f3a8bbc
Theo de Raadt has this potential on the alternative timeline.

------
greyman
Doesn't C have something better than that type punning via union to achieve
the same effect? I understand Linus reasoning, but still it's an ugly hack.

~~~
AstralStorm
Type punning to char* is explicitly allowed. (But going from char* to any
other type is not...)

~~~
hurrrrr
Also you're only allowed to read that char _

------
ezoe
union wasn't designed for the type punning in the first place. It's just
historically used for type punning.

For modern compiler, just use memcpy and compiler can optimize away the memcpy
and produce the exactly same code.

But the kernel developers has some issues on trusting compiler generated code.

------
JakeTyo
This guy writes like an angsty teenager. I find it hard to take him seriously.

------
lifeisstillgood
I Wish I could write like that.

------
mundanevoice
When people can't find fault in the technical argument, they start attacking
other things like. > Oh! He is so rude, He insults so much.

If you have a better argument to counter his logic, please post that, it would
be more useful for everyone involved. Posting pretty useless comments here is
pretty lame.

~~~
strictfp
Wait, so according to you it's OK to be as rude as you wish, as long as you
are technically correct?

I think most people couldn't care less who's right or wrong in this
discussion. They are simply reacting to the discourse.

Personally, I'm far from convinced that there even is an objective right or
wrong in this question. It's probably just a matter of taste and/or
perspective.

I find Linus behavior rude because in discussions like this he seems to have
little to no understanding of other perspectives than his own.

Either that or he is deliberately provoking this other fellow to get him off
his high horses.

In either case, it's not exactly accepted public discourse.

He has said himself that he needs to do this to drive his point across, and
given the medium and audience I can agree that the political challenge of
running the project must be huge.

But surely there must be a more diplomatic way to the same end?

~~~
mundanevoice
> Wait, so according to you it's OK to be as rude as you wish, as long as you
> are technically correct? I never said that. My argument is that
> people/culture are different. What is considered offensive/rude in some
> culture is considered normal in other cultures.

> Personally, I'm far from convinced that there even is an objective right or
> wrong in this question. It's probably just a matter of taste and/or
> perspective.

This is not always true. Sometimes there is only one correct/pragmatic way of
doing something. And if someone asserts that it's nothing wrong.

> I find Linus behavior rude because in discussions like this he seems to have
> little to no understanding of other perspectives than his own.

You can't say this is the case always. I have read a lot of the discussions
like these. A lot of times, he writes a pragmatic and valid explanation of his
dislike about a certain topic.

> In either case, it's not exactly accepted public discourse.

Again, you are assuming all cultures and societies are alike, they are not.
There is a vast wide world with different thinking and a culture other than
the Silicon Valley bubble. It's time people stop generalizing everything under
the sun.

------
mcbits
Here is a slightly more readable version that's not white-on-white, half-
pixel-thick text:
[https://lkml.org/lkml/2018/6/5/769](https://lkml.org/lkml/2018/6/5/769)

~~~
kuschku
Reading on a 400dpi 300nits screen in a slightly dark room, the lkml link
hurts the eyes significantly more.

Reading on a shitty 96dpi 100nits screen from 2004 in a bright room, the lkml
link is the more readable one.

Another situation of the eternal issue of "we need a web standard for
specifying relative contrast", not "make everything blinding #000 on #fff".

~~~
systoll
By the CSS2 standard, #000 and #FFF are sRGB colours, with #000 targeting
0.2cd/m^2, and #FFF targeting 80cd/m^2, with adjustments for ambient light
level.

With CSS4, you can choose other colour-spaces instead.

The web standard is there, but so long as 99% of users have setups which emit
300+cd/m^2 and say they're emitting 80, you can't do much with it.

The push toward HDR displays gives us another chance to 'get it right' wrt
calibration, but a quick google search of 'HDR washed out' demonstrates why
it's an uphill battle to get consumer displays to be honest.

~~~
kuschku
Yeah, it's a major issue — and with CSS there's also no easy way to set HDR
colors either.

Hell most displays nowadays don't even do sRGB, which was defined as the
colorspace and contrast of an average 1990 CRT.

------
nikofeyn
i really wish a person many software engineers idolize or at least obviously
respect and pay attention to, myself being excluded from these camps, didn’t
communicate like a child.

it’s an embarrassment for the field.

~~~
jpttsn
Children communicate like that?

~~~
nikofeyn
yes.

------
coding123
I think we are at the point where someone just needs to put up a Linus
swearing email tracker with analytics and shit and stop posting these threads.
We have to come to the realization that the discussion on this is:

a) useless- doesn't change anything b) the publicity is affecting the other
side more

So basically Linus is Trump

~~~
some_account
I really love that he is the way he is. Smart and honest. Nothing like Trump.

~~~
ankurdhama
Not sure what the word "smart" means but he is surely pragmatic and based on
such emails looks like he gets easily frustrated.

~~~
Techonomicon
He gets frustrated with people that are supposed to be experts but that don't
match up to that in practice (in his eyes at least)

~~~
ankurdhama
Nobody is expert and everybody makes mistakes. He should probably lower his
expectations.

~~~
mundanevoice
You don't write Kernel and maintaining quality by keeping low expectations.

------
maxehmookau
_raises hand_ I would love to be able to contribute to the linux kernel one
day. But I'm unlikely to ever become part of the community when its leader
behaves like this.

~~~
qaq
You have to realize that extreme PC thing is very US centric and pretty recent
at that.

~~~
maxehmookau
I'm not American. I'm just a respectful human being who expects to be treated
with respect at work.

~~~
renox
And in my opinion there was nothing disrespectful in Linus'email (expect
towards the standard people, but they truly did a big mistake..) so I wouldn't
want to work with you as you seem 'overly sensitive'..

~~~
maxehmookau
Big mistakes happen.

Solutions to those mistakes are rarely found by publicly demonising those who
made the mistake.

~~~
ramblerman
> publicly demonising those who made the mistake

But that isn't what is happening here at all. This code was merged. In fact
Linus wasn't even yelling at the guy, rather the standards committee.

Just because you don't read 'atta boy, good job' doesn't mean it wasn't good.
There was no mistake here.

In fact I'd be on your side if that is what he was doing.

