Robby
2009-12-18 18:07:01 UTC
Hello,
I have asked this question in a previous post. I don't mean to double post,
but I would simply like to ask the same question in a more direct manner.
Please consider these .c modules:
=====================KERNEL.h
extern long MQ[];
=====================KERNEL.c
long MQ[10] = {1,2,3,4,5,6,7,8,9,0}; // <<< at top of a particular .c
file!
=====================API.c
#include KERNEL.h // <<< include KERNEL.h header in all .c files that
need MQ[]
void API_InsertMessage(enum enumKM m)
{ MQ[0] = m; }
===========================
Objective:
The data in the MQ array has to be accessible and available in many
functions of several .c files, and therefore should appear to have global
scope.
Resolution:
As shown in code above, I declared an array as "extern" and then defined it
in one .c file and where ever other .c files require access to MQ[], I have
to include the KERNEL.h file. Is this an okay practice to do with all other
global variables, arrays and arrays of structures?
P.S. I am only asking this to assure that I apply the same coding habits for
the rest of my global variables.
In all sincereity, thanks all for any feedback!
I have asked this question in a previous post. I don't mean to double post,
but I would simply like to ask the same question in a more direct manner.
Please consider these .c modules:
=====================KERNEL.h
extern long MQ[];
=====================KERNEL.c
long MQ[10] = {1,2,3,4,5,6,7,8,9,0}; // <<< at top of a particular .c
file!
=====================API.c
#include KERNEL.h // <<< include KERNEL.h header in all .c files that
need MQ[]
void API_InsertMessage(enum enumKM m)
{ MQ[0] = m; }
===========================
Objective:
The data in the MQ array has to be accessible and available in many
functions of several .c files, and therefore should appear to have global
scope.
Resolution:
As shown in code above, I declared an array as "extern" and then defined it
in one .c file and where ever other .c files require access to MQ[], I have
to include the KERNEL.h file. Is this an okay practice to do with all other
global variables, arrays and arrays of structures?
P.S. I am only asking this to assure that I apply the same coding habits for
the rest of my global variables.
In all sincereity, thanks all for any feedback!
--
Best regards
Roberto
Best regards
Roberto