Live data from Hacker News

Linus Torvalds on aliasing

yodaiken.com

91–100 of 284 posts

Re: Linus Torvalds on aliasing

#91
post #63

Earlier quoted context omitted.

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 requi…

memcpy is legal and fine. To borrow the example from above: double d = 3.14; uint64_t i; memcpy(&i, &d, sizeof(d)); is perfectly kosher.

> is perfectly kosher

Aren't exact-bitwidth integer types optional even with C99 (let alone preceding versions of standard)?

Re: Linus Torvalds on aliasing

#92
post #45
post #41

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 ne…

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 { s…

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

Re: Linus Torvalds on aliasing

#93
post #88
post #34

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.…

>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 l…

>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.

Re: Linus Torvalds on aliasing

#94
post #80
post #27

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.

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

And Borland Turbo C, don't forget it.

Re: Linus Torvalds on aliasing

#95

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.

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?

Re: Linus Torvalds on aliasing

#96
post #67

Earlier quoted context omitted.

MIT license, they don't need to. How much code do you think they got back from Sony, Apple, companies selling routers with BSD on them? Even Google prefers to build their own OS from scratch with MIT license (Fuchsia) than keep on using Linux for that effort. They already reduced GPL use to the bare minimum on Android by removing gcc. Then there was the whole suit which made most companies loose interest to be involv…

FreeBSD uses BSD License, no? Or am I missing something here? https://www.freebsd.org/internal/software-license.html

BSD and MIT licenses are almost interchangeable regarding requirements to the code.

They even appear as MIT/BSD in many projects.

Re: Linus Torvalds on aliasing

#97
post #30

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.

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 rea…

Taleb sees swearing as a form of signaling when you have acquired a certain "power" that gives you independence from others. He defends that by publicly swearing and being rude you are actually proving your competence.

See excerpt here: https://twitter.com/nntaleb/status/892370148476190720

Re: Linus Torvalds on aliasing

#98
post #80
post #27

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.

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

Clang was made to support GCC extensions and be as close to a drop-in replacement for GCC as possible. Linux misses support for MSVC, Intel C Compiler, XL C and basically every other C Compiler ever written except for these 2.

Re: Linus Torvalds on aliasing

#99
post #63
post #37

Earlier quoted context omitted.

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;…

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 requi…

C99 and C11 allow type punning via unions (although apparently that only gets mentioned in a footnote)

https://stackoverflow.com/questions/11639947/

Re: Linus Torvalds on aliasing

#100
post #57

Earlier quoted context omitted.

Agree with your points about the suit and Licensing. > Linux only took off thanks to SGI, IBM, HP, Cray seeing value reducing costs from their own in-house systems to something else. This seems unfair, Linux took off because it constantly kept getting improved and has more and more developers contributing to it. It didn't only take off because it was cheap, but it kept on improving. Also, the Elitist mindsets of some…

It is not unfair, because the majority of "developers contributing to it" are on those company payrolls, 8h a day during a full week. It would be just another BSD or Minix if it would be only university students and weekend coders working on it, and we would all keep using Solaris, Aix, HP-UX, Tru64, Ultrix.... As for security issues, it helps that Linus is against disclosing security bugs as such.

> It is not unfair, because the majority of "developers contributing to it" are on those company payrolls, 8h a day during a full week.

This is overwhelmingly true now, but it wasn't always.

Post reply on HN