0

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.

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by WaltP
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.