frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open-source Zig book

https://www.zigbook.net
415•rudedogg•8h ago•158 comments

Britney Spears' Guide to Semiconductor Physics (2000)

https://britneyspears.ac/lasers.htm
157•lachlan_gray•4h ago•54 comments

Supercookie: Browser Fingerprinting via Favicon (2021)

https://github.com/jonasstrehle/supercookie
255•vxvrs•8h ago•53 comments

A new chapter begins for EV batteries with the expiry of key LFP patents

https://www.shoosmiths.com/insights/articles/a-new-chapter-begins-for-ev-batteries-with-the-expir...
50•toomuchtodo•4h ago•14 comments

A 1961 Relay Computer Running in the Browser

https://minivac.greg.technology/
12•vaibhavsagar•1h ago•3 comments

Heretic: Automatic censorship removal for language models

https://github.com/p-e-w/heretic
443•melded•13h ago•168 comments

A File Format Uncracked for 20 Years

https://landaire.net/a-file-format-uncracked-for-20-years/
70•todsacerdoti•1w ago•6 comments

PicoIDE – An open IDE/ATAPI drive emulator

https://picoide.com/
55•st_goliath•4h ago•7 comments

How Your Brain Creates 'Aha' Moments and Why They Stick

https://www.quantamagazine.org/how-your-brain-creates-aha-moments-and-why-they-stick-20251105/
62•wjb3•6h ago•13 comments

The Pragmatic Programmer: 20th Anniversary Edition (2023)

https://www.ahalbert.com/technology/2023/12/19/the_pragmatic_programmer.html
91•ahalbert2•7h ago•11 comments

Dark Pattern Games

https://www.darkpattern.games
152•robotnikman•8h ago•69 comments

What Did Medieval Peasants Know? (2022)

https://www.theatlantic.com/health/archive/2022/05/medieval-history-peasant-life-work/629783/
16•thinkingemote•1w ago•7 comments

I finally understand Cloudflare Zero Trust tunnels

https://david.coffee/cloudflare-zero-trust-tunnels
144•eustoria•10h ago•55 comments

Z3 API in Python: From Sudoku to N-Queens in Under 20 Lines

https://ericpony.github.io/z3py-tutorial/guide-examples.htm
92•amit-bansil•9h ago•3 comments

FPGA Based IBM-PC-XT

https://bit-hack.net/2025/11/10/fpga-based-ibm-pc-xt/
146•andsoitis•12h ago•29 comments

Listen to Database Changes Through the Postgres WAL

https://peterullrich.com/listen-to-database-changes-through-the-postgres-wal
12•pjullrich•5d ago•0 comments

The fate of "small" open source

https://nolanlawson.com/2025/11/16/the-fate-of-small-open-source/
158•todsacerdoti•8h ago•105 comments

What if you don't need MCP at all?

https://mariozechner.at/posts/2025-11-02-what-if-you-dont-need-mcp/
168•jdkee•9h ago•101 comments

I have recordings proving Coinbase knew about breach months before disclosure

https://jonathanclark.com/posts/coinbase-breach-timeline.html
380•jclarkcom•7h ago•127 comments

Fourier Transforms

https://www.continuummechanics.org/fourierxforms.html
108•o4c•1w ago•14 comments

Goldman Sachs asks in biotech Report: Is curing patients a sustainable business? (2018)

https://www.cnbc.com/2018/04/11/goldman-asks-is-curing-patients-a-sustainable-business-model.html
170•randycupertino•5h ago•104 comments

Brimstone: ES2025 JavaScript engine written in Rust

https://github.com/Hans-Halverson/brimstone
201•ivankra•16h ago•96 comments

Why your mock breaks later

https://nedbatchelder.com/blog/202511/why_your_mock_breaks_later.html
20•ingve•5h ago•12 comments

Decoding Leibniz Notation (2024)

https://www.spakhm.com/leibniz
36•coffeemug•9h ago•7 comments

Lithium vs. Lettuce

https://ambrook.com/offrange/photo-essay/lithium-v-lettuce
32•mfburnett•1d ago•6 comments

Linux mode setting, from the comfort of OCaml

https://roscidus.com/blog/blog/2025/11/16/libdrm-ocaml/
46•ibobev•8h ago•4 comments

Anthropic’s paper smells like bullshit

https://djnn.sh/posts/anthropic-s-paper-smells-like-bullshit/
897•vxvxvx•16h ago•274 comments

Call Me Maybe: Eavesdropping encrypted LTE calls with ReVoLTE (2020)

https://montsecure.com/research/revolte-attack/
18•vxvrs•6h ago•4 comments

Show HN: Spam classifier in Go using Naive Bayes

https://github.com/igomez10/nspammer
21•igomeza•1w ago•3 comments

Garbage collection is useful

https://dubroy.com/blog/garbage-collection-is-useful/
123•surprisetalk•14h ago•39 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•6mo ago

Comments

wahern•6mo 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•6mo 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•6mo ago
What language is that? Is it available everywhere (everywhere) C is?
mitthrowaway2•6mo 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•6mo 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•6mo 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•6mo ago
Learning such a language doesn’t mean I can use it.
o11c•6mo 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•6mo 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•6mo 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•6mo ago
This reminds me of the days when Boost was a thing. It was full of tricks like this.
usrnm•6mo ago
It still is a thing, though.
cperciva•6mo 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•6mo 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.