frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

iOS Dev Weekly: Swift Everywhere: Bringing Swift Packages to Android

https://iosdevweekly.com/issues/697/
1•wahnfrieden•41s ago•0 comments

Machine Consciousness Psuedocode

1•cladking•1m ago•0 comments

Nuclear Matters Handbook [pdf]

https://www.acq.osd.mil/ncbdp/nm/NMHB2020rev/docs/NMHB2020rev.pdf
1•handfuloflight•1m ago•0 comments

Ted Chiang on Superintelligence in "The Hampdenshire Wonder"

https://lithub.com/ted-chiang-on-superintelligence-and-its-discontents-in-j-d-beresfords-innovative-work-of-early-20th-century-science-fiction/
1•laacz•2m ago•0 comments

Apple Loses Bid to Dismiss US Smartphone Monopoly Case

https://www.reuters.com/sustainability/boards-policy-regulation/apple-loses-bid-dismiss-us-smartphone-monopoly-case-2025-06-30/
1•jmsflknr•3m ago•0 comments

New band surges to 500k listeners on Spotify, but turns out it's AI slop

https://arstechnica.com/ai/2025/06/half-a-million-spotify-users-are-unknowingly-grooving-to-an-ai-generated-band/
2•Willingham•3m ago•0 comments

Mechanism shrinks when pulled [video]

https://www.youtube.com/watch?v=-QTkPfq7w1A
2•sandebert•4m ago•0 comments

Ukrainians Built a Jammer That Tells Russian Drones They're in Peru

https://daxe.substack.com/p/a-ukrainian-team-built-a-radio-jammer
1•vinnyglennon•4m ago•0 comments

Economic Nihilism

https://www.palladiummag.com/2025/06/30/economic-nihilism/
1•jebarker•4m ago•0 comments

Microsoft AI tool outperforms doctors in diagnosing complex medical cases

https://www.geekwire.com/2025/ai-vs-mds-microsoft-ai-tool-outperforms-doctors-in-diagnosing-complex-medical-cases/
2•JaakkoP•7m ago•0 comments

I still choose no-code vs. vibe code

https://twitter.com/marinatrajk/status/1939774832431780069
3•marince00•8m ago•0 comments

Perplexity Is Doomed

https://medium.com/utopian/perplexity-is-doomed-721abbca1228
3•bentcorner•8m ago•0 comments

How to Opt Out of Your Car's Surveillance State

https://www.carsandhorsepower.com/featured/how-to-opt-out-of-your-car-s-surveillance-state-before-it-s-too-late
2•Anumbia•8m ago•0 comments

Why Don't AI Agents Work (Yet)? [video]

https://www.youtube.com/watch?v=kpOWmwA6tJc
1•ngruhn•8m ago•1 comments

Want to stand out in IT job interviews? a home lab can help

https://www.zdnet.com/home-and-office/want-to-stand-out-in-it-job-interviews-10-ways-a-home-lab-can-help/
2•mooreds•9m ago•0 comments

Space Emerges from Time? Groundbreaking Theory Upends Einstein

https://scitechdaily.com/space-emerges-from-time-groundbreaking-theory-upends-einstein/
2•bookofjoe•10m ago•1 comments

Price of rice in Japan falls below ¥4k per 5 kilograms

https://www.japantimes.co.jp/news/2025/06/24/japan/japan-rice-price-falls-below-4000/
1•PaulHoule•10m ago•0 comments

Japan's Midget Submarine Attack on Pearl Harbor Was a Suicide Mission

https://daxe.substack.com/p/japans-midget-submarine-attack-on
2•vinnyglennon•11m ago•0 comments

Public Signal Backups Testing

https://community.signalusers.org/t/public-signal-backups-testing/69984
1•blendergeek•12m ago•0 comments

The Power of "and": At Bloomberg, Open Source and Corporate Philanthropy

https://www.bloomberg.com/company/stories/the-power-of-and-at-bloomberg-open-source-and-corporate-philanthropy-work-hand-in-hand/
2•pvachon•15m ago•0 comments

Is AI eating your coding skills?

https://jpreagan.com/blog/generative-ai-for-coding/
3•jpreagan•19m ago•0 comments

A simple PWA Hacker News client for desktop

https://hnreader.netlify.app/
3•ClassicOldSong•21m ago•1 comments

Bolivia's Last-Ditch Currency Bet: Spare Change Becomes Crypto Lifeline

https://latinamericanpost.com/economy-en/bolivias-last-ditch-currency-bet-when-spare-change-becomes-crypto-lifeline/
1•dxs•22m ago•0 comments

Show HN: "Computer use" mcp for webapps and Electron apps

https://github.com/snowfort-ai/circuit-mcp
1•clharman•24m ago•0 comments

Building Accurate Address Matching Systems

https://www.robinlinacre.com/address_matching/
1•Bogdanp•26m ago•0 comments

Ring Convolution Networks – Novel neural architecture achieves 90.1% on MNIST

2•bigdatateg1992•26m ago•0 comments

Show HN: Bard – An Experiment in Robot Poetry

https://muffinman.io/bard/
4•stankot•28m ago•1 comments

PewDiePie quits all Google products [video]

https://www.youtube.com/watch?v=u_Lxkt50xOg
2•surprisetalk•28m ago•0 comments

There is no private Email [video]

https://www.youtube.com/watch?v=iH626CXyNtE
2•superpupervlad•28m ago•0 comments

Back end For Front end Authentication in FusionAuth

https://fusionauth.io/blog/backend-for-frontend
1•mooreds•30m ago•0 comments
Open in hackernews

I write type-safe generic data structures in C

https://danielchasehooper.com/posts/typechecked-generic-c-data-structures/
110•todsacerdoti•3h ago

Comments

uecker•2h ago
It is cool trick. I already use in my experimental library though ;-) https://github.com/uecker/noplate/blob/main/src/list.h
eqvinox•1h ago
I guess if anyone might know it might be you—do you see any way of doing this for intrusive data structures, embedding the node struct in the data (and as side effect supporting an object to be on multiple containers) rather than the data in the node like you're doing there?
uecker•43m ago
You could put the dummy member into the embedded node. But for intrusive data structures you often want them to erase the type so that you write generic algorithms as regular functions. In this case, it makes more sense to have a run-time check do to down casts. I do this with my variadic type which has an intrusive "super" member: https://godbolt.org/z/ofdKe7Pfv The overhead is often completely removed by the compiler.
asplake•2h ago
Interesting! I’m working on toy/educational generator of ML-style tagged variants and associated functions in C (for a compiler) and when I’m a bit further along I will see if they’re compatible.
HexDecOctBin•2h ago
The key idea here seems to be to use function pointer's type to enforce type safety rather than using the data "handle" type (that is often found in implementations inspired by Sean Barrett's strechy_buffers).

> One annoying thing about C is that it does not consider these two variables to have the same type

C23 solves that too: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3037.pdf

Supported by latest GCC and Clang, but not by MSVC.

dhooper•2h ago
Author here. Not quite. The key idea is about using a union to associate type information with a generic data type. Type casting a function is not the only way to use that type information. I discuss that as well as the C23 changes in the footnotes and the "typeof on old compilers" section.
eqvinox•1h ago
Interesting idea with the union and using typeof(). We (I) went with large macros defining wrappers instead, which, I believe, is a necessity with intrusive data structures, or at least I don't immediately see how to do that with unions & typeof. Maybe it's possible...?

e.g. hash table wrapper: https://github.com/FRRouting/frr/blob/master/lib/typesafe.h#...

(cf. https://docs.frrouting.org/projects/dev-guide/en/latest/list...)

notnmeyer•1h ago
pretty sure C is the new Go.
revskill•1h ago
Without the concurreny part.
oflebbe•1h ago
OpenMP to the rescue
o11c•1h ago
For your level 2 code, `uint64_t data[];` is wrong for types whose alignment is greater than `uint64_t`, and also wasteful for types whose alignment is smaller (for example, under an ilp32 ABI on 64-bit architectures).

For your level 3 code, it should be `int main() { List(Foo) foo_list = {NULL};`

Note that working around a lack of `typeof` means you can't return anything. Also, your particular workaround allows `const`ness errors since `==` is symmetrical.

You can't safely omit `payload` since you need it to know the correct size. Consider a `List(int64_t)` and you try to add an `int32_t` to it - this should be fine, but you can't `sizeof` the `int32_t`. Your code is actually lacking quite a bit to make this work.

=====

There are 2 major limitations to generics in C right now:

* Delegating to a vtable (internal or external) is limited in functionality, since structs cannot contain macros, only functions.

* Delegating to an external vtable (mandatory to avoid overhead) means that you have to forward-declare all of the types you'll ever use a vtable with. So far the best approach I've found is to declare (but not define) static functions in the same forwarding header I declare the typedefs in; note that GCC and Clang differ in what phase the "undefined static" warning appears in for the case where you don't actually include that particular type's header in a given TU.

(think about writing a function that accepts either `struct SizedBuffer {void *p; size_t len;};` or `struct BoundedBuffer {void *begin; void *end;};`, and also const versions thereof - all from different headers).

EPWN3D•1h ago
I would love for `union`s to be federated, that is, a type could declare itself as thought it was part of a union with another type, without having to pre-declare all possible types in one place.
o11c•1h ago
For layout-compatible types, you can often just include a `_base` member in each child. Maybe twice (once named and once unnamed) to avoid excess typing - I don't understand the common-initial-subsequence rule but people do this enough that compilers have to allow it.
gritzko•1h ago
Hi. I object.

The trick#0 you mention is how I made an entire C dialect. Here is a generic binary heap, for example https://github.com/gritzko/librdx/blob/master/abc/HEAPx.h The syntax is a bit heavyweight, but a huge huge advantage is: you get regular C structs in the end, very plain, very predictable, very optimizable. Compiler would eat them like donuts.

In the other cases, it is void* and runtime memory sizing and you have to define macros anyway.

variadix•1h ago
I agree, there are actually several reasons to prefer the header impl. Debugging is better, both because you can step through the header code where you can’t with a macro function, and because the type information available to the debugger is better. There are more opportunities for compiler optimizations because each instantiation is monomorphized and you don’t pay a runtime cost with variable sizing, generic structures can also be placed on the stack because of the fixed sizing.

There are workarounds for at least two of the problems the author mentions. Naming can be changed from Bar_func(args…) to func(Bar)(args…) with a function name macro that just does name mangling. You can avoid some of the binary bloat by using weak symbols, letting the linker deduplicate functions shared between translation units at link time.

There are other problems for generic containers of pointer types however, you can work around them by using a typedef or a type alias.

Intrusive data structures are more convenient in C still, but working with them in a debugger is a pain.

dhooper•1h ago
Author here. It's worth noting that no work is being done in the macros of my article, they compile down to a normal c function call which you can step through in a debugger.

There is little benefit in monomorphizing the implementation of a data structure like a linked list where its behavior doesn't depend on the contents of the data it contains (compared to, say, a max heap)

dhooper•1h ago
Author here. Binary heaps and linked lists are different use cases. A binary heap must read the data you put in it to store it correctly, but a linked list doesn't. If I were writing a generic binary heap, maybe I would weigh my options differently. I mentioned this in the footnotes.
knutwannheden•57m ago
> Compiler would eat them like donuts.

Made me laugh out loud!

b0a04gl•1h ago
what happens if two types have same size and alignment but different semantics : like `int` vs `float` or `struct { int a; }` vs `int`? does the type tag system catch accidental reuse . aka defending against structual collisions
ape4•1h ago
Or write in CFront and have it translated to C
layer8•1h ago
The casting of the function type assumes that the item pointer type (e.g. Foo*) has the same representation as void*, which the C standard doesn’t guarantee (in standardese: the two types aren’t “compatible”). Calling the function with the converted type therefore constitutes undefined behavior. It also impacts aliasing analysis by compilers (see [0], incidentally), even if the pointer representation happens to be the same.

This casting of the functions to different argument types constitutes the core of the type safety of the generic invocations; I’m not sure it can be fixed.

[0] https://news.ycombinator.com/item?id=44421185

dhooper•40m ago
This is addressed in the footnotes. casting is not the core of the type safety. Read the whole article.
layer8•19m ago
Ah, that’s what I get for not reading the footnotes. However, the alternative solution presented evaluates the item argument twice, which is problematic as well (but could probably be worked around by passing `(list)->payload` on instead). Secondly, the assignment for type-checking doesn’t work for read-only operations on a const List, or does it? And doesn’t the assignment overwrite the head? Lastly, the do-while construction means you can’t use it for operations that return a value (without compiler extensions).

I also don’t agree it’s “squeamish” to be wary of aliasing analysis going wrong. It’s not a clean abstraction and can hide subtle bugs down the road.

monkeyelite•57m ago
Another way is to not try to write generic data structures. When you tailor them to the use case you can simplify.

The #1 data structure in any program is array.

hgs3•51m ago
I'm curious what a hashmap looks like with this approach. It's one thing to pass through or hold onto a generic value, but another to perform operations on it. Think computing the hash value or comparing equality of generic keys in a generic hashmap.
mfuzzey•47m ago
There's also the method used in the Linux kernel to embed the list information (struct list_head) within the type specific struct. https://kernelnewbies.org/FAQ/LinkedLists
cherryteastain•45m ago
Why would you jump through all these hoops instead of just writing C++ if you want "C with generics"
Kranar•42m ago
Because for many of the use cases where C is used, switching to C++ involves jumping through even more hoops.
lionkor•31m ago
Do you have a couple of real world examples?
adastra22•25m ago
Embedded systems, for example.
teraflop•1m ago
I know it used to be, but is it really still common for embedded systems to use weird architectures that G++ doesn't support?
mikepurvis•23m ago
Any established C codebase, for example the kernel or Postgres?

Traditionally microcontroller firmwares as well, though those are increasingly friendly to C++, you just have to be careful about allocations as C++ makes it way easier to accidentally allocate than C does.

rectang•22m ago
Writing extensions for projects that support C extensions but may not support C++ extensions, e.g. many dynamic languages.
Snarwin•2m ago
You can still write the extension in C++ and expose an extern "C" interface.