Hacker News new | ask | show | jobs
by PaulHoule 318 days ago
I still use C to write little programs for Ardunio but it drives me nuts thinking about all the useless stuff C is doing with the stack and calling convention when I could just use global variables for everything and sometimes even use nothing but registers for inner loop variables.

I stick with C because (1) I'd have to figure out the tooling for 100% assembly development on AVR-8, and (2) C is portable to other platforms so if I want to migrate to an ARM or ESP-32 board it would be easy. (The upward migration path for AVR-8 is to go to a soft core on an FPGA but talk about frying pan to the fire)

3 comments

I've been trending towards "C with namespaces" for Arduino on AVR-8.

With namespaces you can have globals and few collisions. At the expense of more typing, of course.

You do know about the "register" storage class/keyword, I am sure. Sometimes it works.

Edit - the tooling for AVR assembler seems to be avr-gcc and make. Check out Nerd Ralph's "ArduinoShrink" library for an example of blended C and assembler:

https://github.com/nerdralph/ArduinoShrink/tree/master

The 100kloc thing had no malloc/free, ie most significant persistent data objects were static, and the inlining with LTO (and some help) was pretty intense, so the stack was used, but not as much as it seemed on the surface. We did (re)invent some carefully managed buffers shared through several levels of call, since we were doing, for example, AES-GCM: https://github.com/opentrv/OTAESGCM
Yeah, the stack can be such a headache. I remember how much pain I went through just trying to wrap my head around it — even gave up a few times.

But then I’d cool down… and come back to it. Some languages just never “clicked” for me, but somehow I keep coming back to C.