This page has been designed specifically for the printed screen. It may look different than the page you were viewing on the web.
Please recycle it when you're done reading.

The URI for this page is { http://cc.byexamples.com }

extern, variable define else where Posted on January 18th

Sometimes we might need to declare global variable. Let say I have 5 files (cat.c, dog.c, tiger.c, rabbit.c and animal.c). I declare a global integer variable “debug” at animal.c

int debug;

In order to let other modules from other file besides animal.c to gain the global access, I need to add a line for ( cat.c, dog.c, tiger.c and rabbit.c).

extern int debug;

I use debug global variable to store the value of debug mode. With different debug mode, I can control what to print on screen to ease the debugging.

Trackback URL
Leave your own comments about this post: