HNHacker News
TopNewBestAskShowJobs

david2ndaccount

1,147 karma · joined February 28, 2020

blog: https://www.davidpriver.com
submissionscomments
david2ndaccount··on On social reality in China
Weird to talk about these traits like Chinese cynicism and generational trauma without even mentioning the Great Leap Forward and Cultural Revolution.
david2ndaccount··on C's Flexible Integer Sizes Were Not a Design Mistake
I’m sorry but this is just incorrect. When you take the address of a thread local variable you have to lookup its real address using something like __tls_get_addr or by reading its offset via fs/gs but once it’s in a pointer it’s just a regular absolute address and is fine to dereference on any thread. There is no separate type for a pointer to a thread local variable.
david2ndaccount··on C's Flexible Integer Sizes Were Not a Design Mistake
I don’t know what you mean, if you take the address of a thread local variable you get a regular pointer which is just as safe to dereference as any other pointer, cast through intprt_t or not?
david2ndaccount··on C's Flexible Integer Sizes Were Not a Design Mistake
`thread_local` is a storage class, there is no `thread_local T*` in the same way there is no `static T*`
david2ndaccount··on C extensions, portability, and alternative compilers
Use the new standards-conformant preprocessor with `/Zc:preprocessor`

https://learn.microsoft.com/en-us/cpp/build/reference/zc-pre...

david2ndaccount··on Use string views instead of passing std:wstring by const&
Pascal strings might be the only string design worse than C strings. C Strings at least let you take a zero copy substring of the tail. Pascal strings require a copy for any substring! Strings should be two machine words - length + pointer (aka what is commonly called a string view). This is no different than any other array view. Strings are not a special case.
david2ndaccount··on TSMC to make advanced AI semiconductors in Japan
The world won’t allow a dependence on a single geopolitically threatened entity in the long run, so either they defuse that risk themselves or risk a competitor filling that role. This move is better for TSMC itself.
david2ndaccount··on C/C++ Embedded Files (2013)
If you want to remain portable, write your code in the intersection of the big 3 - GCC, Clang and MSVC - and you’ll be good enough. Other implementations will either be weird enough that many things you’d expect to work won’t or are forced to copy what those 3 do anyway.
david2ndaccount··on C/C++ Embedded Files (2013)
You can apply `#` to __VA_ARGS__, which won’t preserve the exact whitespace, but for many languages it’s good enough. biggest issue is you can’t have `#` in the text.
david2ndaccount··on How to write generics in C
I wrote a similar article in the past: https://www.davidpriver.com/ctemplates.html

I use this technique in my hobby projects as it has worked out the best for me of the options I’ve explored.

david2ndaccount··on Recursive macros in C, demystified (once the ugly crying stops)
Works with MSVC if you add /Zc:preprocessor (to get a standard compliant preprocessor instead of the legacy one).
david2ndaccount··on Writing memory efficient C structs
The author relies on the compiler fitting the bitfield in unused padding bytes after “speed”, but that is implementation-defined behavior (almost everything about bitfields is implementation defined). MSVC will align the unsigned bitfield to alignof(unsigned), whereas GCC and clang will use the padding bytes. To portably pack the struct, use unsigned integers and use flags (monster.flags & CAN_FLY instead of monster.can_fly).

See https://c.godbolt.org/z/K7oY77KGj

david2ndaccount··on Writing memory efficient C structs
C23 has _Float16
david2ndaccount··on “Reading Rainbow” was created to combat summer reading slumps
Summer reading programs are a band-aid on the problem that children shouldn’t have such a long summer break now that air conditioning is common. Spread the breaks out throughout the year if you want to maintain the same number of days off. All evidence shows the summer break is bad for children’s academic achievement (especially poor children), but it is viewed as a perk for the teachers so the teacher’s unions fight against questioning it.
david2ndaccount··on Would You Like an IDOR With That? Leaking 64m McDonald's Job Applications
> We immediately began disclosure of this issue once we realized the potential impact. Unfortunately, no disclosure contacts were publicly available and we had to resort to emailing random people. The Paradox.ai security page just says that we do not have to worry about security!

Amazing.

david2ndaccount··on I write type-safe generic data structures in C
The “typeof on old compilers” section contains the code:

         (list)->payload = (item); /* just for type checking */\
That is not a no-op. That is overwriting the list head with your (item). Did you mean to wrap it in an `if(0)`?
david2ndaccount··on Variadic Switch
In D, you can just do a static foreach over a sequence to generate case labels:

https://d.godbolt.org/z/PxWEW14K1

david2ndaccount··on DoorDash to acquire Deliveroo
Don’t ignore food addiction, the app turns into a button you can press on your phone and in a bit you’ll have a dopamine hit from the food. You don’t have to get dressed or confront the reality of your situation.
david2ndaccount··on Driving Compilers (2023)
That’s not the point of hello world. It’s not to be as small a valid program as possible. It’s to be a small program that also exercises the needed functionality for using the tool usefully. All of the exercises following that hello world need formatted text, so introducing puts would just add confusion and wouldn’t verify that you have a working printf.
david2ndaccount··on Converting a Git repo from tabs to spaces (2016)
Tabs are a control character and have no business being in a text file. Do you use ascii record separator characters too?
david2ndaccount··on An Introduction to Modern CMake
You’re switching to the build system of a different, pre 1.0 programming language that has frequent breaking changes?
david2ndaccount··on Better typography with text-wrap pretty
This does actually look a lot better. Using the inspector to toggle it on and off, “pretty” does look a lot prettier.
david2ndaccount··on WorstFit: Unveiling Hidden Transformers in Windows ANSI
Backslash is a valid path character (you can use / or \ as the path separator on windows) so if the backslash isn’t actually escaping anything it is left as-is.
david2ndaccount··on MacKenzie Scott donates over $2B in 2024 to 199 organizations
let not thy left hand know what thy right hand doeth
david2ndaccount··on Show HN: A portable hash map in C
If you’re interested in this, I wrote a blogpost on a simple c hash table without deletion.

https://www.davidpriver.com/c-hash-table.html

david2ndaccount··on OpenAI, Google and Anthropic are struggling to build more advanced AI
Without a non-linear activation function, chaining perceptrons together is equivalent to one large perceptron.
david2ndaccount··on Don't return named tuples in new APIs
You can have methods with NamedTuple
david2ndaccount··on Type-erased generic functions for C: A modest non-proposal
I wrote a blogpost describing this technique. https://www.davidpriver.com/ctemplates.html
david2ndaccount··on The 4-chan Go programmer
Somewhat a reference to https://wiki.c2.com/?ThreeStarProgrammer
david2ndaccount··on Tony Hawk's Pro Strcpy
Only msvc provides strcpy_s and they don’t conform to the standard. Other libcs don’t provide it. Ignore everything from Annex K and write your own wrappers around memcpy. You should always know the size of your buffers.
Page 1 of 9Next →