Live data from Hacker News

C++: Zero-cost static initialization

cofault.com

51–60 of 60 posts

Re: C++: Zero-cost static initialization

#51

Earlier quoted context omitted.

> Every time someone ships successful code that's hard to port to Windows Until your boss tells you to port your so-far Linux-only code to Windows, and you run that struggle. Signed, someone who spent the past year or so porting Linux code to Windows and macOS because the business direction changed and the company saw what was the money-maker. P.S. Not the parent commenter, because I just realised they, too, had a pa…

Can you setup Windows to install WSL if it isn't there yet and then set it up, in a Windows installer?

We actually tried that at first.

The technical requirement of installing WSL before installing our software was already a non-starter, since most Windows users expect one installer or zip to do-it-all. WSL2 isn't (yet) like a C/C++/DirectX redistributable which can be plugged in as a dependency to a given program. Additionally our program is expected to work natively with Windows paradigms.

More critically, we work with high-performance filesystems. The performance impact of files going a round-trip through the Linux Plan9 driver, then through a Linux kernel context switch, into the kernel, and down into Hyper-V, and then up back through the Windows Plan9 driver was completely unacceptable. It was deemed worthwhile to rewrite targeting Windows natively. And even then it was only a partial rewrite: we ended up using MinGW because we had too much of a direct dependency on the pthread API.

Re: C++: Zero-cost static initialization

#52
post #50

Earlier quoted context omitted.

Windows and *nix are different platforms. Writing crossplatform code is pretty easy and a solved problem. At least 99.5% of code can be platform agnostic. Only a few tiny bits are special. My background is video games. Which is well known to be a Windows-first environment. I currently work on robotics. The vast majority of robotics ecosystem code is Unix only. You know what is extremely useful for teleoperation? Virt…

You're complicit with Windows living on, being long overdue in the landfill of computing history.

Disrespectfully disagree.

Re: C++: Zero-cost static initialization

#53

> For this we need a certain old, but little-known feature of UNIX linkers STOP WRITING NON-PORTABLE CODE YOU BASTARDS. The correct answer is, as always, “stop using mutable global variables you bastard”. Signed: someone who is endlessly annoyed with people who incorrectly think Unix is the only platform their code will run on. Write standard C/C++ that doesn’t rely on obscure tricks. Your co-workers will hate you le…

Author here. This is part of SPDK-based server code. Transportability outside of UNIX (mostly Linux) is entirely irrelevant. By the way, the global variables here are immutable after the initialisation, that's the point.

Re: C++: Zero-cost static initialization

#54

Earlier quoted context omitted.

I think that would cause some surprising behavior changes for certain code changes, not something that C++ (or any language) needs more of.

Which is why it should have been sorted out decades ago.

I mean when making (apparently) small changes to the initialization of the static even in the proposed new system.

Re: C++: Zero-cost static initialization

#55

Earlier quoted context omitted.

> Every time someone ships successful code that's hard to port to Windows Until your boss tells you to port your so-far Linux-only code to Windows, and you run that struggle. Signed, someone who spent the past year or so porting Linux code to Windows and macOS because the business direction changed and the company saw what was the money-maker. P.S. Not the parent commenter, because I just realised they, too, had a pa…

Can you setup Windows to install WSL if it isn't there yet and then set it up, in a Windows installer?

wsl also has the issue that when windows decides to auto update and there is a wsl update while there is a wsl instance running, it will just kill it right there and then to carry on with the update.

This has bitten me once when I was doing a distro upgrade and windows just killed the WSL vm midway.

Re: C++: Zero-cost static initialization

#56

Earlier quoted context omitted.

I'm not sure what to think. What argument do you have for your position?

Windows and *nix are different platforms. Writing crossplatform code is pretty easy and a solved problem. At least 99.5% of code can be platform agnostic. Only a few tiny bits are special. My background is video games. Which is well known to be a Windows-first environment. I currently work on robotics. The vast majority of robotics ecosystem code is Unix only. You know what is extremely useful for teleoperation? Virt…

When I'm writing software, I'm writing it for me, not anyone else. I use linux. If I decide to release anything I wrote, I am under no obligation, nor am I "ethically compelled" to make it cross platform. I wrote it for me. Use it or not.

Re: C++: Zero-cost static initialization

#57

Earlier quoted context omitted.

Can you setup Windows to install WSL if it isn't there yet and then set it up, in a Windows installer?

wsl also has the issue that when windows decides to auto update and there is a wsl update while there is a wsl instance running, it will just kill it right there and then to carry on with the update. This has bitten me once when I was doing a distro upgrade and windows just killed the WSL vm midway.

Even if I now MS Windows can be annoying (why I don't use it), I'm completely out-of-touch with the hoops MS Windows user have to jump to have a usable computer. This is kind-of also a disadvantage, because you can't anticipate bugs that you can't imagine.

Re: C++: Zero-cost static initialization

#58
post #16

Earlier quoted context omitted.

Every time someone ships successful code that's hard to port to Windows the world becomes a better place.

> Every time someone ships successful code that's hard to port to Windows Until your boss tells you to port your so-far Linux-only code to Windows, and you run that struggle. Signed, someone who spent the past year or so porting Linux code to Windows and macOS because the business direction changed and the company saw what was the money-maker. P.S. Not the parent commenter, because I just realised they, too, had a pa…

just curious, what would be the business direction to "Linux-only code"? Don't need any trade secrets, just quick expression on the area/target auditory.

I.e. - I have tried WSLg (running GUI apps in WSL) but disabled it all together, as after running xclock and couple of things like that to ensure it works, I couldn't find any interest in running GUI apps on Linux.

I can somewhat imagine need for work purposes, if you are falling into some webdev area and need to run some tests against local browser, but that's different from my POV.

Re: C++: Zero-cost static initialization

#59

Earlier quoted context omitted.

> Every time someone ships successful code that's hard to port to Windows Until your boss tells you to port your so-far Linux-only code to Windows, and you run that struggle. Signed, someone who spent the past year or so porting Linux code to Windows and macOS because the business direction changed and the company saw what was the money-maker. P.S. Not the parent commenter, because I just realised they, too, had a pa…

just curious, what would be the business direction to "Linux-only code"? Don't need any trade secrets, just quick expression on the area/target auditory. I.e. - I have tried WSLg (running GUI apps in WSL) but disabled it all together, as after running xclock and couple of things like that to ensure it works, I couldn't find any interest in running GUI apps on Linux. I can somewhat imagine need for work purposes, if y…

> what would be the business direction to "Linux-only code"

Deep interaction with Linux filesystem and kernel behaviour; we've done some intercepting and trampolining Linux syscalls in run-time, and tying it all up to cloud storage APIs.

We had to fundamentally re-architect some of our code to support macOS and Windows.

Re: C++: Zero-cost static initialization

#60

> For this we need a certain old, but little-known feature of UNIX linkers STOP WRITING NON-PORTABLE CODE YOU BASTARDS. The correct answer is, as always, “stop using mutable global variables you bastard”. Signed: someone who is endlessly annoyed with people who incorrectly think Unix is the only platform their code will run on. Write standard C/C++ that doesn’t rely on obscure tricks. Your co-workers will hate you le…

Author here. This is part of SPDK-based server code. Transportability outside of UNIX (mostly Linux) is entirely irrelevant. By the way, the global variables here are immutable after the initialisation, that's the point.

Unless you missed it from another comment in this thread, the optimization you made is based on a wrong assumption and misreading the asm code: "je .L3" will skip all the costs you consider.
Post reply on HN