News for hackers. Stuff that matters.

raible

Re:Fun Extending the C Preprocessor on Sunday October 18, 2026 @05:33PM (#50145698)
I use something like this to turn __VA_ARGS__ into count/pointer:

  // Create a stack-allocated argv from N args gcc, clang, tcc, mingw, msvc, etc
  // argc is always correct, for portability argv has a dummy element when argc==0
  // This avoids problematic 0-length compound literal arrays.
  #define _ARG_CV(type, ...)  _ARG_CV1(((type []){0, __VA_ARGS__}))
  #define _ARG_CV1(array)     _ALEN(array) - 1, array + (_ALEN(array) > 1)
  #define _ALEN(array)         sizeof array / sizeof *array
Then it's just:

  #define sum(...) sum(_ARG_CV(int, __VA_ARGS__))
Re:Ask HN: What Are You Working On? (October 2024) on Monday October 28, 2024 @01:59PM (#41974090)
I'm working on a PEG-based Turing complete language. It is self-hosted, generates standalone/embedable C, is reasonably small, and comes with a fully-featured REPL. It has only a single keyword: "macro". Feel free to reach out if interested.
Re:Infinite Craft on Wednesday January 31, 2024 @04:24PM (#39209626)
Weed + tree = bong!
Re:7.1M miles, 3 minor injuries: Waymo's safety data looks good on Thursday December 21, 2023 @02:35PM (#38725598)
Getting rear-ended is almost always the other driver's fault, but 7 years ago I was involved in a serious accident (minor injuries, both cars totaled) when the driver in the fast lane decided to pull over and pick up a hitchhiker. Crossed over two lanes, hard on the brakes, and I had no chance to even get off the gas.

The responsibility was 100% his because of "an unsafe lane change".

Well, maybe. I for one _absolutely_ didn't participate b.c. I didn't want my DNA and personally identifying information owned by any company. I can't imagine that there aren't many others like me.

I would, however, love to send my DNA to a company if they could provide the results without knowing any information about me whatsoever. For instance: I would be more than willing to buy the kit with cash and send it back with a burner email. Has anyone heard of such a service?

Re:Did you know Git was originally created in 10 days? on Friday September 08, 2023 @03:07PM (#37437981)
It's hard to imagine either Linux or Git if Ken Thompson and Dennis Ritchie hadn't laid the foundation.
I can highly recommend libtcc (https://github.com/TinyCC/tinycc.git) for this kind of thing. I recently ported the code developed in linux on an ARM chromebook to a generic windows box in 20 minutes.
Re:Show HN: Yaksha Programming Language on Sunday March 19, 2023 @08:24PM (#35225436)
Perhaps https://github.com/TinyCC/tinycc would be useful? I've had success using it to implement a repl for my language.
Re:Ask HN: What's your secret diet tip you can share? on Monday December 26, 2022 @01:23AM (#34135218)
Not exactly a diet tip, but first thing every day (after stretching) I drink a large glass of water (16oz), drink another large glass with a tablespoon or so of psyllium husk, then another large glass of water. Then whatever breakfast I feel like. Psyllium is cheap, safe, and readily available (and most of us should be eating more fiber, right?).
Re:Extism: Make all software programmable with WebAssembly on Thursday December 01, 2022 @05:35PM (#33823944)
I've had great success with a fourth way: my project language compiles to C, which is loaded at runtime with libtcc (specifically: git://repo.or.cz/tinycc). I've gone down the .so/.dll route a few times in the past, but I can safely say: never again. libtcc has the advantages of a jit (native C speed), but with an elegant API and laudable portability.
Re:A tiny C header-only RISC-V emulator on Tuesday November 29, 2022 @09:06PM (#33796037)
This is an awesome project. In the video you mention that you might drop it... please don't!
Re:In Defense of Linked Lists on Saturday November 05, 2022 @11:20PM (#33488554)
Thanks for that, it's what I had hoped for (but again, have not yet measured).

It seems to me it's a super-handy way of "modifying" a compiler-allocated array of structs. I'm sticking with it!

Re:In Defense of Linked Lists on Friday November 04, 2022 @11:32PM (#33477604)
FWIW I usefully use a "fake" linked list by adding a .next field to the struct in a compiler-allocated array of structs. On initialization I set the list head to &item[0], and in a trivial loop set the .next field of each entry (except the last) to entry+1.

Why bother? Because I can then easily add a few extra structs to the beginning of the (contiguously-allocated) linked-list without having to reallocate the whole thing.

Sure, pointer chasing with separately allocated structs is "slow", but I haven't yet measured to see if it's any different when (almost all) items are contiguous.

If you would... - what sort of cache behavior should one expect of this on a modern laptop CPU? - I haven't seen this approach before, have you?

Re:Bringing a dynamic environment to C: My linker project on Friday October 28, 2022 @10:17PM (#33380339)
I have found the libtcc from https://github.com/TinyCC/tinycc to be absolutely fantastic. I'm using it to instantaneously compile the C output from my hobby language to create a repl. Once I had the compiler in good shape it allowed me to create a 100% compatible interpreter for (basically) free.

The libtcc API is minimal. For my needs that has been 100% sufficient and a pleasure to work with.

Thanks for asking!

I've been working on a PEG-based Turing-complete language which creates completely standalone and trivially-embedded C. The "selling point" would be "A DSL for creating DSLs".

In the last few weeks I've been working on a libtcc-based add-on in order to build a REPL to help create/explore a desired grammar interactively.

Actually, the course number back then was 6.031. I only become 6.001 later on.
Re:I Don't Like Debuggers (2000) on Friday March 22, 2019 @02:11PM (#19465235)
WGAF? I don't like source code control systems.

;)