implementation of rand()

Check out this collection of random number generators from George Marsaglia. He’s a leading expert in random number generation, so I’d be confident using anything he recommends. The generators in that list are tiny, some requiring only a couple unsigned longs as state. Marsaglia’s generators are definitely “high quality” by your standards of long period … Read more

What is a jump table?

A jump table can be either an array of pointers to functions or an array of machine code jump instructions. If you have a relatively static set of functions (such as system calls or virtual functions for a class) then you can create this table once and call the functions using a simple index into … Read more

Why are global variables bad, in a single threaded, non-os, embedded application

It wouldn’t. The two fundamental issues with global variables is simply cluttering the namespace, and the fact that “no one” has “control” over them (thus the potential collisions and conflict with multiple threads). The “globals are bad”, like pretty much every other computer programming idiom is a guideline, not a hard and fast rule. When … Read more

How do you implement a class in C? [closed]

That depends on the exact “object-oriented” feature-set you want to have. If you need stuff like overloading and/or virtual methods, you probably need to include function pointers in structures: typedef struct { float (*computeArea)(const ShapeClass *shape); } ShapeClass; float shape_computeArea(const ShapeClass *shape) { return shape->computeArea(shape); } This would let you implement a class, by “inheriting” … Read more