I have a file of 14 functions. I know I need an extern array of 14 bools. If something goes wrong in one of these functions, the function should modify its respective array member to false. I want the main program to be able to access the array members to verify if upon execution of one of these functions the array number of that function became false (function alerted something went wrong).

I know I can do this easier other ways, but I have to do it with extern and I cannot get the linkage to work because I cannot understand it well enough.

There will also be a utility function ran at the start of the main program that will set all array members to true by default:

void init_flags()
{
    int i;

    for (i = 0; i < NFLAGS; i++)
        exit_flags[i] = true;
}

Any tips on where and how I declare the extern variable would be greatly appreciated.

EXTERN simply defines the variable to be accessible from a another source file. Add the EXTERN statement in a local header file and define the variable in only one of the source files.

For example, in the error.c source file you might define int errCode = 0; In error.h you define extern int errCode; and #include this file in each source you need the errCode variable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.