HNHacker News
TopNewBestAskShowJobs

unwind

12,407 karma · joined March 23, 2009

Bearded hacker from Sweden. Learned M68k assembly on the Amiga in the late 80s. Compiling C on a 7 MHz CPU was slow. Working as a contracting software developer since almost 10 years, enjoying visiting various parts of the software world.

I hang out a lot on Stack Overflow: http://stackoverflow.com/users/28169/unwind, mainly answering questions about C. I love C.

submissionscomments
unwind··on The Cost of a Closure in C
Of course, `&&` in C is short-circuiting so it's safe without the `strlen()` too, as long as the argument is there i.e. not NULL.

Also, the use of a convoluted `if` to conditionally assign a literal boolean is a code smell (to me), I would drop the `if` and just use:

    in_reverse = argc > 0 && argv[1][0] == '-' && argv[1][1] == 'r';
if a more forward-thinking/strict check is not needed.
unwind··on Joyboard is a balance board peripheral for the Atari 2600
Wow!

I vaguely remember a reference to some balance game as the origin story for the Guru Meditation, but that was so long ago and I never looked it up!

Meta: it would have been nice to include this reference in the submission title, since it's least as interesting as the fact that the peripheral was for the Atari 2600. Something like "The Joyboard: Atari 2600 balance peripheral that inspired Guru Meditation", perhaps. Probably too late now, and this is not exactly tearing down the front page, anyway. :)

Thanks!

unwind··on A supersonic engine core makes the perfect power turbine
That is the most William Gibson thing I've read today, at least. Wow.
unwind··on Brent's Encapsulated C Programming Rules (2020)
Uh, okay, but if you need to constantly write code as if people reading it don't understand the language, then ... I don't know how to do that. :)

It's not possible to know C code and think that

    sizeof *v
and

    sizeof v
somehow mean the same thing, at least not to me.
unwind··on Brent's Encapsulated C Programming Rules (2020)
Where would you put it? The const of the pointer is not the main point, it's just extra clarity that the allocated pointer is not as easily overwritten which would leak the memory.
unwind··on Brent's Encapsulated C Programming Rules (2020)
Quite interesting, and felt fairly "modern" (which for C programming advice sometimes only means it's post-2000 or so). A few comments:

----

This:

    struct Vec3* v = malloc(sizeof(struct Vec3));
is better written as:

    struct Vec3 * const v = malloc(sizeof *v);
The `const` is perhaps over-doing it, but it makes it clear that "for the rest of this scope, the value of this pointer won't change" which I think is good for readability. The main point is "locking" the size to the size of the type being pointed at, rather than "freely" using `sizeof` the type name. If the type name later changes, or `Vec4` is added and code is copy-pasted, this lessens the risk of allocating the wrong amount and is less complicated.

----

This is maybe language-lawyering, but you can't write a function named `strclone()` unless you are a C standard library implementor. All functions whose names begin with "str" followed by a lower-case letter are reserved [1].

----

This `for` loop header (from the "Use utf8 strings" section:

    for (size_t i = 0; *str != 0; ++len)
is just atrocious. If you're not going to use `i`, you don't need a `for` loop to introduce it. Either delete (`for(; ...` is valid) or use a `while` instead.

----

In the "Zero Your Structs" section, it sounds as if the author recommends setting the bits of structures to all zero in order to make sure any pointer members are `NULL`. This is dangerous, since C does not guarantee that `NULL` is equivalent to all-bits-zero. I'm sure it's moot on modern platforms where implementations have chosen to represent `NULL` as all-bits-zero, but that should at least be made clear.

[1]: https://www.gnu.org/software/libc/manual/html_node/Reserved-...

unwind··on The Lost Machine Automats and Self-Service Cafeterias of NYC (2023)
it's been .. too long, but Amsterdam used to feature lots of food vending machines and it seems like they're still there [1]!

[1]: https://dutchreview.com/dutch-quirks/dutch-quirk-107-eat-foo...

unwind··on The Lost Machine Automats and Self-Service Cafeterias of NYC (2023)
Interesting, did some light (heh) digging.

[1] agrees that World War II-era luminous materials featured radium, yes. Another use seems to have been putting discs on helmet fronts of paratroopers, to help soldiers see each other in the dark.

This page [2] has a picture of a variety of luminous products from the era, and also mentions one civilian usage was marking edges of clothing, also to help make pedestrians more visible in the (blacked-out) streets.

I'm rather low on the Interest in History scale, but it's fascinating how often WW2 manages to deliver something new. Thanks.

[1]: https://www.paratrooper.be/articles/luminous-disks/

[2]: http://www.butterflybalcony.com/2013/10/the-home-front-black...

unwind··on Dollar-stores overcharge customers while promising low prices
The article touches on this:

All told, 69 of the 300 items came up higher at the register: a 23% error rate that exceeded the state’s limit by more than tenfold.

This implies that an error rate of perhaps 2% would be legal. I haven't checked, but I guess Europe has something similar even though I'm quite certain that retailers have to sell things at the posted price if there's a mistake.

Part of the problem seems to be that the maximum fine (at least in the state in the article) is "too low", so retailers don't have an incentive to keep price tags correct since they profit from the error and even if they're fined it's still better (economically) for them to charge more than the price tag. I wonder how much lobbying has happened to keep fines low ...

unwind··on The C++ standard for the F-35 Fighter Jet [video]
For C, the proper/expected/standard way to reference a variable without accessing it is a cast to void:

    (void) a;
I'm sure there are commonly-implemented compiler extensions, but this is the normal/native way and should always work.
unwind··on Multivox: Volumetric Display
I think it's worth pointing out that "in operation" here means it's running Doom. Which I was not expected, and somewhat blown away (heh) by. Very very cool.
unwind··on What is better: a lookup table or an enum type?
I don't database, but I like to think I have some kind of intuition for storage space requirements, and this article was very confusing.

Ignoring the indexes and just focusing on the main table sizes reported, we have:

- String ("The frequent repetition of these names inflates the size of the table"): 392 MB

- Enum data type ("Internally, an enum type is stored as four-byte floating point number. So it saves space in the table [...]"): 338 MB

- Lookup table ("Also, since a smallint only occupies two bytes, the person_l table can potentially use less storage space than the other solutions"): 338 MB.

I just can't make sense of the numbers, especially given the authors comments that I've quoted.

Is this some kind of typo/editing fail?

unwind··on Addressing the adding situation
Not in C no, since arithmetic on a pointer is implicitly scaled by the size of the value being pointed at (this statement is kind of breaking the abstraction ... oh well).
unwind··on Spleen Monospaced Bitmap Fonts
TIL the term "throw-up", thanks!

It's weirding me out that Wikipedia's page features graffiti of the word ... SPLEEN to illustrate [1]. Wut.

[1]: https://en.wikipedia.org/wiki/Throw_up_(graffiti)

unwind··on Engineers repurpose a mosquito proboscis to create a 3D printing nozzle
This is cool and great and all, but isn't it a bit ... stretched to motivate this by the fact that the nozzle is biodegradable?

I mean for a printing nozzle with an inner diameter of 20 µm, how much material would be wasted if it was made out of plastic or metal? I get that no such nozzle is available and/or easily made, but shouldn't that be the point of the invention, rather than "yay, it's biodegradable so we save a microgram of plastic/metal"?

unwind··on Implementing Bluetooth LE Audio and Auracast on Linux Systems
This:

If you've ever wondered why your music quality drops dramatically when you answer a call on your Bluetooth® headset, you've experienced one of A2DP's key limitations firsthand.

Made me feel old ... how are people listening to music while taking a call?

unwind··on Vsora Jotunn-8 5nm European inference chip
It loaded fine for me, but that slash before the unit was a bit smelly. :| Just a tiny edit, but it's a rather core part of their message so they should probably notice and format it correctly before publishing.
unwind··on Rethinking C++: Architecture, Concepts, and Responsibility
The article argues that modern C++ has type-checked string formatting, so it does not argue for (unchecked) `printf()`, right?
unwind··on The feds want to make it illegal to even possess an anarchist zine
According to Wikipedia, the writing was (mostly?) by Brian Reynolds [1]. There's an interview [2] which is linked to by the Wikipedia page about the game [3].

[1]: https://en.wikipedia.org/wiki/Brian_Reynolds_(game_designer)

[2]: https://web.archive.org/web/20050221102608/http://pc.ign.com...

[3]: https://en.wikipedia.org/wiki/Sid_Meier%27s_Alpha_Centauri#I...

unwind··on Git 3.0 will use main as the default branch
Tip: the next time you need to name a function, don't use "a stupid word that doesn't say much about anything". That's not how you're supposed to name stuff in programming. :)
unwind··on Show HN: I wrote a minimal memory allocator in C
This looked nice and simple, appreciated!

A couple of minor C points:

- The code seems to completely lack use of `static` for things that should be local to the implementation, such as `META_SIZE`, `find_free_block()` and others.

- The header includes `<stdbool.h>` but the interface doesn't use it so it could be included in the C file instead (which, in fact, it is!).

- Could do with more `const` for clarity, but that is quite personal.

- Interesting to use explicit comparison to check for integers being zero, but treat pointers being NULL as implicit boolean. I prefer comparing in both cases.

unwind··on Show HN: F32 – An Extremely Small ESP32 Board
Me too, but that particular picture was confusing. Shouldn't the board be with the human, 120 ft from the wifi access point being connected to? Now it looks as if the human screams at the board from 120 ft away, or something.

Other than that, hugely impressive project of course, it makes any board I've tried to design/assemble look impossibly huge. :)

unwind··on Show HN: Reversing a Cinema Camera's Peripherals Port
Neat! It's great when old hardware can be made better and given new features (and extending the life-span) by semi-simple means like this. It's also amazing to see how often a 3D printer pops up in these projects, nowadays.

This paragraph stood out a little to me:

We only need two pins (which the STM32 is total overkill for): GND and a GPIO. The only thing really making this harder than just turning it on/off is that we need to both read the voltage and write it but this protocol is so slow you can literally just change the type on the fly lol—or as we are doing, just making it both an in- and output.

There's like two levels of semi out of the box thinking here: one is the solution the OP came up with, the fact that even if a pin is in output mode, the input circuitry often still just works so you can read the pin. The other is of course to connect the signal to one more external pin (the OP even made a point of there being a huge abundance of pins) and program that as a permanent input (electrically I believe this is safe, inputs are high-impendance, but a series resistor wouldn't hurt for semi-low speed signals as far as I know).

unwind··on Where do the children play?
By the way the rest of the (actual) saying that is the title for the Swedish book is "Only Bad Clothes". In Swedish it rhymes [1] which of course increases its power. I know it from when I was a kid 40+ years ago, and I think both my kids would recognize it or at least get the meaning.

That being said, obviously mobile phones etc are huge and (in my opinion) problematic among kids here, too.

[1]: https://www.reddit.com/r/Svenska/comments/vj2630/no_such_thi...

unwind··on Laptops with Stickers
Somewhere I have a "RUN GCC" sticker from the Free Software Foundation that I was given by Daniel Stenberg (author of curl) at some meetup here in Stockholm.

That would actually be kind of cool, I always end up not being able to make up my mind about what would be worthy.

unwind··on Drawing Text Isn't Simple: Benchmarking Console vs. Graphical Rendering
Meta: this is kind of a repost, not even a month since last time [1].

[1]: https://news.ycombinator.com/item?id=45580559

unwind··on Myna: monospace typeface designed for symbol-rich programming
Repost, see https://news.ycombinator.com/item?id=45849342.
unwind··on The Linux Kernel Looks to “Bite the Bullet” in Enabling Microsoft C Extensions
Huh. I thought the article was vague on what exactly these extensions permit, so I'd thought I'd look up the GNU documentation. Surprisingly, it [1] was rather vague too!

The only concrete example is:

Accept some non-standard constructs used in Microsoft header files.

In C++ code, this allows member names in structures to be similar to previous types declarations.

    typedef int UOW;
    struct ABC {
      UOW UOW;
    };

[1]: https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#in...
unwind··on Patching 68K Software – SimpleText
I believe the reasoning for the "Intel style" ("op dst, src") is that it reads more like "dst = src" which is how it's written in higher-level languages.
unwind··on A Fond Farewell
Nobody posted [1] yet, it feels like it's needed.

[1]: https://en.wikipedia.org/wiki/Long_Now_Foundation

← PreviousPage 3 of 34Next →