I have this function:
void bs_gmm(IMG in_img,struct bs_gmm_var *gmm_ctxt,IMG *bg_msk,IMG *bg_img)
in which I am declaring some variables like:
int num_models,num_features;
float lr,update_factor;
float deviation_thresh;
int std_dev_int;
The thing is that when I am trying to define or use these variables — for example:
num_models=gmm_ctxt->num_models;
I am getting two errors:
Regarding
num_models
:This declaration has no storage class or type specifier
and
gmm_ctxt
:gmm_ctxt is undefined
I know that local variables are by default auto storage class and also I had specified the type of the variable; why do I get this type of error?
The function call is from main()
which is in another source file.
I know that I am overseeing something. Forgive me for my ignorance.
I had declared the above mentioned function in a header file and I had included it in both the source files concerned.
The structure bs_gmm_var is declared in a header and i had included it in both the source files concerned.The declaration goes as follows
typedef struct bs_gmm_var
{
MEAN mean;
STD_DEV std_dev;
WEIGHT weight;
CLASSIFICATION_STATE classification_state;
RANK rank;
RANK_INDEX rank_index;
int *match_array;
float *prob_feature;
int num_models;
float lr;
float update_factor;
float deviation_thresh;
float assign_thresh,dying_thresh;
float std_dev_int;
int intialize_state;
int width;
int height;
int num_features;
int num_frames;
};
Then i declared a pointer to the above structure in the main function.This pointer along with another structure is sent to the following function.
The structure bs_gmm_var is defined in the function shown below:
void intialize_params(struct bs_gmm_var **gmm_ctxt,struct config_params bs_config_params)
{
struct bs_gmm_var *gmm_stats;
int width=bs_config_params.width;
int height=bs_config_params.height;
int num_features=bs_config_params.num_features;
int num_models=bs_config_params.num_models;
// Allocate memroy for whole structure
gmm_stats = (bs_gmm_var *)malloc(sizeof(bs_gmm_var));
gmm_stats->mean=(float*)calloc(num_models*num_features*width*height,sizeof(float));
.
.In this way i have allocated memory for other members(from mean to prob_feature)
.
gmm_stats->prob_feature=(float *)malloc(num_features*sizeof(float));
gmm_stats->num_models=bs_config_params.num_models;
gmm_stats->lr= bs_config_params.lr;
.In this way other members(from num_models to num_frames)are also defined
.
gmm_stats->num_frames=bs_config_params.num_frames;
*gmm_ctxt = gmm_stats;
}
As you can see this defines the structure bs_gmm_var through the pointer gmm_stats. Now,the pointer which i had sent to the above function as the address of the structure(through the pointer gmm_stats) which is defined.That pointer i am sending it to the function:
void bs_gmm(IMG in_img,struct bs_gmm_var *gmm_ctxt,IMG *bg_msk,IMG *bg_img)
Both errors point to
struct bs_gmm_var
being undefined. Make sure to include the right header file, or define the structure before that function in the code.To confirm the definition of the structure, running the code through the preprocessor and looking at the output can help. With
gcc
that'sgcc -E ...
using the same compiler flags (except those used for linking).