NaSh
NaSh

Reputation: 665

error for unused variable, gem5

I am using scons to compile gem5.

scons build/ARM/gem5.fast -j4

I have defined a variable, initialized it and used it in dprintf statement.

Addr tot_blk_count = page_number / page_per_block; 
DPRINTF(out, "Total block count %lu " , tot_blk_count); 

However, scons will report errors (not warning) for unused variables.

 error: unused variable 'tot_blk_count' [-Werror=unused-variable]

Any suggestion on how to get rid of this error, or change it to warning?

Upvotes: 1

Views: 410

Answers (1)

NaSh
NaSh

Reputation: 665

While compiling for gem5.fast DPRINTF will be ignored, and tot_blk_count will be an unused variable.

Solutions:

One solution is to compile for gem5.opt, since it will not ignore the DPRINTF and no error will be reported.

scons build/ARM/gem5.opt 

Second solution is to use the statement inside DPRINTF to avoid unused variable in case you are compiling for gem5.fast:

DPRINTF(out, "Total block count %lu " , page_number / page_per_block);

In case you want to keep the declaration of the unused variable, simply mark it with M5_VAR_USED, which will inform the compiler that the variable is possibly unused and no warning will be triggered:

Addr M5_VAR_USED tot_blk_count = page_number / page_per_block; 
DPRINTF(out, "Total block count %lu " , tot_blk_count); 

Upvotes: 1

Related Questions