Takeaways from the book “Advanced C Programming” by Berry, John Thomas.

While it’s titled “advanced”, it is rather basic. Here is some quick notes on stuff that I’m not familar with/ don’t use often.

define variables as global to a small region of program

Global variables always involves the possibility of side effects. By keeping the coupling well controlled, we minimize some of this danger.

// stack and top are global to push() and pop(), but hidden from main().
void push();
void pop();
int main(){
// calling push() and pop()

int top;
void* stack[100];

void push(){
// .. pushing to the stack

void* pop(){
// .. popping from the stack

Using stack to hide global variables from the rest of the program


// stack and top can still be accessed here
// by declaring them with extern.
// or worse, main.c can declare them as global again
// causing problems...

extern void* stack[];
extern int top;
int main(){


int top;
void* stack[100];
void push(){...};
void pop(){...};

to avoid this, declare the global variables as static so that their scopes are restricted only to the home file.

static double stack[100];
static int top=0;

Declaring functions in main to limit the scope: only use there!

int main(
int foo();


int foo(){
// ...


typedef struct _bf{
    int f1:1,

int main(){
    flags bf;
    bf.f1 = 0;
    bf.f2 = 1;
    bf.f3 = 1;

    // check flag
    if(bf.f1) // do ..