Hacker News

New stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. Alibaba Contributing $3M USD to Omarchy to Work on Making "Ideal" Agentic OS(phoronix.com)
    discuss
  2. Too much or too little sleep may make your body age faster(sciencedaily.com)
    discuss
  3. A gardening game that takes 48 real days to grow one zucchini(ihaveagarden.com)
    discuss
  4. Implementing the esoteric "Brainfuck" language in Carp Lisp [video](youtube.com)
    discuss
  5. Capita lacks the 'capacity and ability' to run GP pension scheme, BMA tells MPs(computerweekly.com)
    discuss
  6. Notes from the SF Safety Scene(12gramsofcarbon.com)
    discuss
  7. The Economics of Open-Weight Inference(ornn.com)
    discuss
  8. Texas police department ordered to close for failing to provide public benefit(dallasnews.com)
    discuss
  9. The draft AI code of conduct forbids me from saying 'I don't know'(ilands.ai)
    discuss
  10. Time to Spend Tokens or Meditate?(inmve.github.io)
    discuss
  11. It's the Fun(scottsumner.substack.com)
    discuss
  12. SEO Content Brief: What to Include for Better Rankings(briefiq.io)
    discuss
  13. Expat 2.8.5 released, fixes vulnerability CVE-2026-93990(hartwork.org)
    discuss
  14. A First Futamura Projection(veitheller.de)
    discuss
  15. Show HN: IntelliChat minimalist, open-source UI for local and cloud AI(github.com/intelligentnode)
    discuss
  16. Differential Equations, an Interactive Introduction(chapterpal.com)
    discuss
  17. A Simple Guide to Calm UI(maxschmitt.me)
    1comments
  18. Anthropic at $2T isn't far-fetched(ft.com)
    1comments
  19. Firedrill: Stateful tool simulation for AI agents(github.com/firedrill-tools)
    discuss
  20. Carefully Applied: Resume and LinkedIn Rewriting(carefullyapplied.com)
    discuss
  21. iPhone 15 Pro and 16 Settlement for Apple Intelligence taking claims – US ONLY(smartphoneaisettlement.com)
    discuss
  22. Nvidia Isaac ROS 5.0: agentic, open-source robotics development(nvidia.com)
    discuss
  23. Toadstools and Toxins(aeon.co)
    discuss
  24. Remote Code Execution (RCE) in a DoD Website(hackerone.com)
    1comments
  25. People Training OpenAI's AI Fired for Using AI to Train the AI(404media.co)
    discuss
  26. Worker Previews: isolated preview for every change your agent makes(cloudflare.com)
    discuss
  27. Websites that read in the terminal: the TermWeb standard(andros.dev)
    discuss
  28. Devin AI and SWE-2 First Impressions(catalins.tech)
    discuss
  29. George Lucas Museum Review: A Bold Throwback to Gilded Age Patronage(hollywoodreporter.com)
    discuss
  30. AI Is Antithetical to Learning(jola.dev)
    1comments

Type Punning in C and C++

34 pointsby 2h agoblog.pwkf.org
19 comments
1h agoHN ↗

Does reinterpret_cast works in c++ for this?

1h agoHN ↗

The C vs C++ distinction here is genuinely treacherous

What's so genuine about this?

1h agoHN ↗

Despite the fact they're two different languages, people are often taught as though it's basically just a subset relationship and then they carry this through into the actual software they write.

Because neither of these are memory safe languages, you are required to ensure you've made no mistakes or else anything might happen.

1h agoHN ↗

It continues with

and most blog posts on the topic get it wrong.

This smells like Claudism/LLMish.

1h agoHN ↗

The example included below "Why C and C++ Differ" is UB in both C and C++ (and says nothing about "why" C & C++ differ). The article isn't overall wrong but that bit is just...

(Feels a bit like LLM junk, but honestly not sure.)

57m agoHN ↗

A pointer cast worked fine at -O0 and silently broke at -O2.

Feels like LLM to me. I looked at some of the rest of the article and... pretty much certain now.

16m agoHN ↗

(Feels a bit like LLM junk, but honestly not sure.)

Why leave such disparaging comments?

11m agoHN ↗

Because if the comment is correct, it's useful signal for other potential readers to know that they can skip it.

I try to be as charitable as possible when reading and commenting online, but we don't have infinite attention and thanks to AI, it's easier than ever to end up wasting it on things that aren't worth reading.

(I'm not claiming that the article here is or is not an example of that.)

8m agoHN ↗

Even if it's not from an LLM, it's still wrong! You've focused on the last important of that comment, really.

1h agoHN ↗

Is it necessary to use the lowest possible font weight?

52m agoHN ↗

I just watched video[0] that argues if you can consteval something, then it must be free of UB, which seems compelling, at least for these lower level helpers.

Unfortunately, it seems memcpy is not constexpr, so cannot be used like this, but std::bit_cast actually works[1] as constexpr, so I think in C++ that would now be the most preferred use. It won't allow the union either.

[0] https://www.youtube.com/watch?v=-LAXqqqX274 [1] https://godbolt.org/z/xGzjTMGvv

13m agoHN ↗

__builtin_memcpy is constexpr under clang with constraints

7m agoHN ↗

Careful, only language UB is guaranteed to be detected in constant evaluation, UB in standard library functions isn't. It is a good sanity check though.

Also it seems that bit_cast in particular is going to be strengthened in this regard:

https://cplusplus.github.io/LWG/issue4539

38m agoHN ↗

The conclusion is simply wrong. `union` should not be used for type-punning in C++, or in C code which might be compiled by a C++ compiler.

I can't downvote posts yet, but if you have the ability, consider it. This is clearly LLM slop without human review.

32m agoHN ↗

I don't understand the example in "Why C and C++ Differ".

Shouldn't the code return 3 in the base case and 4 if the check for 2 was assumed to always hold ?

2m agoHN ↗

You're halfway there. It's a little more messed up than that.

IIRC, this is all little-endian. So assume our 8 bytes labeled A-H. For a 32 bit/4 byte integer, they will be read as DCBA. For a 64 bit/8 byte integer, HGFEDCBA.

So the struct is set up like a = DBCA, b = HGFE. So when we assign 2 and 3 to a and b, it should look like this in memory:

00000010 00000000 00000000 00000000 and 00000011 00000000 00000000 00000000

When we cast that to a uint64 and assign 4 to it, we should wind up with:

00000100 00000000 00000000 00000000 00000000 00000000 00000000 00000000

Which effectively zeros out b.

So if the conditional is evaluated, it will evaluate to false, we return b, which is 0.

If the conditional is not evaluated, we should return the value in a, which is 4.