logoalt Hacker News

jdlshorelast Monday at 4:25 AM2 repliesview on HN

My understanding is that global variables are more common in embedded systems because it provides memory determinism.


Replies

Glawenlast Monday at 7:51 AM

Yep that's the standard in embedded on bare metal without memory allocation. There is a mechanism in place to synchronise data during interrupts, so it's not really direct write. Usually also coupled with a two complement variable or similar to make sure memory is not corrupted for safety critical data.

monegatorlast Monday at 5:21 AM

nah, by looking ad other people's firmware it's because most of my embedded colleagues are goats stuck in pre-ANSI C. You can always declare a "global" static, so it's not on the stack or heap, and access that via functions.

Nothing wrong with source-file-level statics, you're bound to use them