GCC is saying snr_db is unused when I set -Wall flag, but this variable is used. When i initialize it outside the scope of the for, gcc stops warning me. Does anyone know why is that?
double snr_db;
double snr_db_step = #WHATHEVER
for (int interval = 1, snr_db = 20.0; interval <= intervals; interval++, snr_db -= snr_db_step) {
snr_lin = pow(10.0, snr_db / 10.0);
bit_err_rate = ber_bpsk(snr_lin);
//CODE CONTINUES
}
Actually it is not used. You declared it double
-
double snr_db; // this is unused
But in the for
loop-
for (int interval = 1, snr_db = 20.0; ..)
In this snr_db
is int
here (this is same case as int x,y;
, both are int
as being part of declaration) and over shadows the one declared above this loop body.
Therefore, double snr_db;
remains unused.
You could do this-
double snr_db;
int interval;
for(interval = 1, snr_db =20.0;..){....} // only intialization
/* ^^^^^^^^^^^^^^^^^^^^^^^^ this would be a different case from above as here
',' does work as comma operator therefore, evaluating both the expressions. */
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With