Global Constructors and Destructors with C (not C++)

In the OOP world, global objects get initialized with a constructor and destroyed at the end with a destructor. Interestingly, the GNU gcc has attributes to mark functions as constructor and destructors, which can greatly simply system startup and shutdown, even if not using C++.

C Function marked as Constructor and called before main()

With the GNU gcc compiler, I can mark functions with an attribute, so they get called before entering main() or after exit of main(). The attribute works both in C and C++, but it especially useful in C to initialize modules in an automated way.

Continue reading

Spilling the Beans: Endless Loops

The university lectures are kind of ‘back to normal’: with the COVID certificates mandatory, many former limitations (social distance, masks, …) have been relaxed. So this means there are now many more questions and discussions with students.

One of the thing I realized is that I am doing things in a certain way, and I don’t need to think about it, because I have used certain techniques for a long time. So I had several discussions last week with students which I would characterize as “aus dem Nähkästchen plaudern”. No real ‘secrets’, but just things which might be a something new to think about. Well, I think this is worth a potential new blog article series if this continues, so here we go with a first one: how to write ‘endless’ loops in C?

Photo by Pixabay on Pexels.com
Continue reading