From: Robby on
"Victor Bazarov" wrote:

> > long MQ[]={1};
>
> Here you're defining an array whose name has external linkage. As soon
> as you include this header in more than one .c file, you get multiply
> defined symbol. Don't do that. Definitions belong to the .c files, not
> to headers.

the data in the MQ array has to be accessible and available for the KERNEL.c
and API.c modules. Having said this, (mind you I didn't try this) but, can I
just declare it in KERNEL.h like this:

=====================KERNEL.h
extern long MQ[];

>>>and have it available in the following modules by doing this?

=====================KERNEL.c
long MQ[10] = {1,2,3,4,5,6,7,8,9,0}; // <<< at top of file!

=====================API.c
#include "API.h"
#include KERNEL.h // <<< include the header with MQ declaration.

void API_InsertMessage(enum enumKM m)
{ MQ[0] = m; }
===========================

> > QUESTIONS:
> > 1) This including stuff is a mess *to me that is* I still don't see the
> > advantage of including every .h files in .c files.
>
> There is probably no advantage. Include only the headers you actually
> need in that module.

Okay!

> > 3) Is the following function okay?
> >
> > ===================================
> > void API_InsertMessage(enum enumKM m)
> > {
> > long MQ_LOC;
> > MQ[MQ_LOC] = m;
> > }
> > ==================================
>
> No. Not OK by a mile. First off, you don't initialize 'MQ_LOC' and
> immediately attempt to use it as the index. That's a disaster waiting
> to happen.
[snip]

Sorry my typo, it was supposed to be:
===================================
void API_InsertMessage(enum enumKM m)
{
long MQ_LOC;
MQ_LOC = KERNEL_find_next_empty_queue_spot(...);
MQ[MQ_LOC] = m;
}
==================================

>Second, what's 'MQ'? What's 'enumKM'? Did you define
> those? Are they known to the compiler at this point?

Yes, it is defined at the top of KERNEL.h.

> > The reason I am asking is that MPLAB generates the following error:
> >
> > API.c:3: error: parameter `m' has incomplete type
>
> Perhaps you forgot to include the header that defines 'enumKM' type...

But I did include KERNEL.h which is where I declare enumKM type ???

> From the looks of it, enough to keep you busy for a while. But isn't
> it actually good? I mean, guaranteed employment an so on...

Work is always good. Thanks for the encouragement!
Thank you for your help! If you can, do get back!

Robert