Gcc unused-but-set-variable warning for mutable

I have a small function that writes values ​​to HW using a mutable variable

void gige_rx_prepare(void) {

    volatile uint hw_write;

    // more code here

    hw_write = 0x32;
}

Version gcc version 4.7.3 (Altera 13.1 Build 162) places this variable as set, but is not used, although being volatile, it makes writing HW registers easier.

I would like to see this warning for any other variable. Is there a way to avoid this warning about mutable variables without resorting to setting gcc attributes for every mutable variable in the code?

+3
source share
1 answer

A local variable is not a good representation of the h / w register and that part of the reason you see the warning.

(), hw_write . , , . volatile uint, , , , - .

- :

volatile int hw_write2;  // h/w register
void gige_rx_prepare2(void) {


    // more code here

    hw_write2 = 0x32;
}

void gige_rx_prepare3(void) {
    volatile int *hw_write3 = (void*)0x1234; // pointer to h/w register.


    // more code here

    *hw_write3 = 0x32;
}
+4

All Articles