frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Bring Back Idiomatic Design

https://essays.johnloeber.com/p/4-bring-back-idiomatic-design
126•phil294•3h ago•52 comments

Show HN: Oberon System 3 runs natively on Raspberry Pi 3 (with ready SD card)

https://github.com/rochus-keller/OberonSystem3Native/releases
58•Rochus•3h ago•4 comments

Seven countries now generate 100% of their electricity from renewable energy

https://www.the-independent.com/tech/renewable-energy-solar-nepal-bhutan-iceland-b2533699.html
180•mpweiher•2h ago•66 comments

JVM Options Explorer

https://chriswhocodes.com/vm-options-explorer.html
112•0x54MUR41•5h ago•53 comments

Tell HN: docker pull fails in spain due to football cloudflare block

210•littlecranky67•3h ago•76 comments

Eternity in six hours: Intergalactic spreading of intelligent life (2013)

https://www.researchgate.net/publication/256935390_Eternity_in_six_hours_Intergalactic_spreading_...
14•wallflower•1h ago•5 comments

AI Will Be Met with Violence, and Nothing Good Will Come of It

https://www.thealgorithmicbridge.com/p/ai-will-be-met-with-violence-and
245•gHeadphone•7h ago•424 comments

Phyphox – Physical Experiments Using a Smartphone

https://phyphox.org/
109•_Microft•7h ago•20 comments

Anthropic downgraded cache TTL on March 6th

https://github.com/anthropics/claude-code/issues/46829
275•lsdmtme•10h ago•191 comments

Happy Map

https://pudding.cool/2026/02/happy-map/
103•surprisetalk•5d ago•16 comments

A Tour of Oodi

https://blinry.org/oodi/
44•zdw•2d ago•9 comments

Compute iOS XNU offset from kernel cache

https://blog.reversesociety.co/blog/2026/kernel-rw-not-enough-extract-offsets-from-xnu-kernelcaches
8•tonygo•2d ago•0 comments

Tell HN: OpenAI silently removed Study Mode from ChatGPT

117•smokel•2h ago•32 comments

I run multiple $10K MRR companies on a $20/month tech stack

https://stevehanov.ca/blog/how-i-run-multiple-10k-mrr-companies-on-a-20month-tech-stack
550•tradertef•10h ago•330 comments

Pro Max 5x quota exhausted in 1.5 hours despite moderate usage

https://github.com/anthropics/claude-code/issues/45756
410•cmaster11•3h ago•354 comments

We have a 99% email reputation. Gmail disagrees

https://blogfontawesome.wpcomstaging.com/we-have-a-99-email-reputation-gmail-disagrees/
114•em-bee•3h ago•101 comments

The Physics of GPS

https://perthirtysix.com/how-does-gps-work
36•maouida•5h ago•4 comments

Doom, Played over Curl

https://github.com/xsawyerx/curl-doom
41•creaktive•6h ago•4 comments

How We Broke Top AI Agent Benchmarks: And What Comes Next

https://rdi.berkeley.edu/blog/trustworthy-benchmarks-cont/
448•Anon84•21h ago•109 comments

The Miller Principle (2007)

https://puredanger.github.io/tech.puredanger.com/2007/07/11/miller-principle/
56•FelipeCortez•5d ago•45 comments

An Interview with Pat Gelsinger

https://morethanmoore.substack.com/p/an-interview-with-pat-gelsinger-2026
84•zdw•2d ago•50 comments

Tofolli gates are all you need

https://www.johndcook.com/blog/2026/04/06/tofolli-gates/
101•ibobev•5d ago•29 comments

Small models also found the vulnerabilities that Mythos found

https://aisle.com/blog/ai-cybersecurity-after-mythos-the-jagged-frontier
1182•dominicq•23h ago•318 comments

Internet outage in Iran reaches 1,008 hours

https://mastodon.social/@netblocks/116384935123261912
95•miadabdi•4h ago•40 comments

Floyd's Sampling Algorithm

https://buttondown.com/jaffray/archive/floyds-sampling-algorithm/
6•ibobev•5d ago•0 comments

How Complex is my Code?

https://philodev.one/posts/2026-04-code-complexity/
153•speckx•5d ago•40 comments

447 TB/cm² at zero retention energy – atomic-scale memory on fluorographane

https://zenodo.org/records/19513269
240•iliatoli•20h ago•133 comments

Dark Castle

https://darkcastle.co.uk/
222•evo_9•20h ago•29 comments

Pijul a FOSS distributed version control system

https://pijul.org/
185•kouosi•5d ago•27 comments

Apple Silicon and Virtual Machines: Beating the 2 VM Limit (2023)

https://khronokernel.com/macos/2023/08/08/AS-VM.html
215•krackers•19h ago•151 comments
Open in hackernews

Detecting if an expression is constant in C

https://nrk.neocities.org/articles/c-constexpr-macro#detecting-if-an-expression-is-constant-in-c
49•signa11•11mo ago

Comments

wahern•11mo ago
> This works. But both gcc and clang warn about the enum being anonymous... even though that's exactly what I wanted to do. And this cannot be silenced with #pragma since it's a macro, so the warning occurs at the location where the macro is invoked.

You can use _Pragma instead of #pragma. E.g.

  #define C(x) ( \
    _Pragma("clang diagnostic push") \
    _Pragma("clang diagnostic ignored \"-Wvisibility\"") \
    (x) + 0*sizeof(void (*)(enum { tmp = (int)(x) })) \
    _Pragma("clang diagnostic pop") \
  )
EDIT: Alas, GCC is a little pickier about where _Pragma is allowed so you may need to use a statement expression. Also, it seems GCC 14 doesn't have a -W switch that will disable the anonymous enum warning.
pjc50•11mo ago
It's remarkable that people will say that doing this kind of thing is better than learning a language which actually lets you enforce this with the type system.

(or even just insist that users use the version of the language which supports "constexpr"!)

oguz-ismail•11mo ago
What language is that? Is it available everywhere (everywhere) C is?
mitthrowaway2•11mo ago
Indeed, usually if I'm using C these days it's because I only have access to a c compiler for my target platform, or because I'm modifying an existing C codebase.
uecker•11mo ago
I do not think anybody said this. The point is that these macros work for early versions of C. If you need to support early versions of C, learning another language is not a solution. If you don't have to, you can use C23's constexpr.
trealira•11mo ago
C used to seem like a beautiful and simple language to me, but as I used it and learned more about it, it seemed more complex under the surface, and kind of janky as well. It's just utilitarian.
wat10000•11mo ago
Learning such a language doesn’t mean I can use it.
o11c•11mo ago
The problem is that no such language exists.

There are many languages that provide one particular feature that C doesn't provide, but they do this at the cost of excluding numerous other features that C widely relies on.

kjs3•11mo ago
"I have no idea what problem you're trying to solve, what the constraints are, what the use cases might be, what tools are available on the platform, what the job or regulations require, what the skillsets of the people involved are, what the timeline is...but I'm absolutely, unshakably certain that I have a magic bullet that will make all your problems go away."

FTFY.

sleirsgoevy•11mo ago
The Linux kernel has even a way to determine whether the expression is compile-time, WITHOUT aborting compilation in either case.

The trick is this (copied vebratim from Linux):

#define __is_constexpr(x) (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))

Explanation: if x is a constant expression, then multiplying it by zero yields a constant 0, and casting a constant 0 to void* makes a null pointer constant. And the ternary expression, if one of its sides is a null pointer constant, collapses to the type of the other side (thus the type of the returned pointer will be int*, and the sizeof will match). And if x was not constant, then the lefthand side would not be considered a null pointer constant by type inference, the type of the ternary expression will be void*, and the sizeof check will not match.

With a few more clever tricks, it's even possible to implement a compile-time "type ternary expression", like this: TYPE_IF(2 * 2 == 4, int, long). This is left as an exercise for the reader.

amelius•11mo ago
This reminds me of the days when Boost was a thing. It was full of tricks like this.
usrnm•11mo ago
It still is a thing, though.
cperciva•11mo ago
With a few more clever tricks...

I did this with my PARSENUM macro (https://github.com/Tarsnap/libcperciva/blob/master/util/pars...) to parse strings into floating-point, unsigned integer, or signed integer types (and check bounds) using a single interface.

bobbyi•11mo ago
I thought this would work:

#define C(x) (sizeof(char[x]), x)

sizeof is a compile-time operation so x need to be known at compile time.

It didn't work as expected. It turns out there is an exception and the standard says that sizeof is actually calculated at runtime specifically for variable length arrays:

> The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. The size is determined from the type of the operand. The result is an integer. If the type of the operand is a variable length array type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an integer constant.