This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

STATIC_ASSERT and GCC (instead of Keil)

I'm bringing up ble_app_hrs as an eclipse project using gcc.

I'm running into an error in app_util.h, line 67:

#define STATIC_ASSERT(EXPR) typedef char static_assert_failed[(EXPR) ? 1 : -1]

The error is:

typedef 'static_assert_failed' locally defined but not used [-Werror=unused-local-typedefs] ble_app_hrs line 67, external location: ..../nrf51822/Include/app_common/app_util.h C/C++ Problem

I believe the instance of STATIC_ASSERT it's complaining about is in app_timer.c, line 1035:

STATIC_ASSERT(APP_TIMER_INT_LEVELS == 3);

QUESTION: what's up with this? Is there some kind of support I need to add so this mechanism will work correctly?

  • As far as I can see, this is a consequence of using GCC 4.8q4, in combination with -Werror, which turns all warnings into errors. Earlier versions of GCC have not given a warning on this construct, but it seems 4.8 does.

    The application note is written for a previous version of GCC, but there shouldn't be any problems by using later versions if you just solve this one. That can either be done by removing the -Werror flag from line 60 of Makefile.common, or fix app_util.h as follows:

    
    #define STATIC_ASSERT(EXPR) typedef char static_assert_failed[(EXPR) ? 1 : -1] __attribute__((unused))
    
    
  • Thanks! That did the trick. I'm now ale to build 5.1.0 with gcc.

  • Hello to every one,

    i must compile some .c and .h file in a project, am using MPLAB-X-IDE 6.20 and avr gcc 7.3.0 (for program my ATMega644P mcu).

    the error up it seems like my errors, please can you rewrite for me this lines? thank you.

    Compiler is unable to compile follow lines:

    _Static_assert(__builtin_offsetof(struct SysTick_Regs, CALIB) == 0x1c - 0x10, "struct SysTick_Regs has incorrect size");

    give me error: lpc17xx/lpc176x.h:62:42: error: "(" may not appear in macro parameter list
    make[2]: Entering directory 'C:/Users/Leonardo/Documents/Elettronica 2014/Download Project/ATmega/C-64-SdCardDrive/sd2iec-MPlab/ds2iec-mega644pV1.0.0'
    "C:\Program Files (x86)\GNU Avr-8-bit toolchain\bin\avr-gcc.exe" -mmcu=atmega644p -I "C:/Program Files/Microchip/MPLABX/v6.20/packs/Microchip/ATmega_DFP/3.1.264/include" -B "C:/Program Files/Microchip/MPLABX/v6.20/packs/Microchip/ATmega_DFP/3.1.264/gcc/dev/atmega644p" -x c -c -D__ATmega644P__ -funsigned-char -funsigned-bitfields -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -MD -MP -MF "build/default/production/lpc17xx/llfl-ar6.o.d" -MT "build/default/production/lpc17xx/llfl-ar6.o.d" -MT build/default/production/lpc17xx/llfl-ar6.o -o build/default/production/lpc17xx/llfl-ar6.o lpc17xx/llfl-ar6.c -DXPRJ_default=default
    make[2]: Leaving directory 'C:/Users/Leonardo/Documents/Elettronica 2014/Download Project/ATmega/C-64-SdCardDrive/sd2iec-MPlab/ds2iec-mega644pV1.0.0'
    #define _Static_assert(__builtin_offsetof(struct SysTick_Regs, CALIB) == 0x1c - 0x10) typedef char static_assert_failed[(__builtin_offsetof(struct SysTick_Regs, CALIB) == 0x1c - 0x10) ? 1 : -1] __attribute__((unused))

    and so on (all errors):

    _Static_assert(__builtin_offsetof(struct SCB_Regs, BFAR) == 0x38, "struct SCB_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct NVIC_Regs, STIR) == 0xf00 - 0x100, "struct NVUC_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_GPDMA_Regs, DMACSync) == 0x34, "struct LPC_GPDMA_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_GPDMACH_Regs, DMACCConfig) == 0x10, "struct LPC_GPDMACH_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_GPIO_Regs, FIOCLR) == 0x1c, "struct LPC_GPIO_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_GPIOINT_Regs, IO2IntEnF) == 0xb4 - 0x80, "struct LPC_GPIOINT_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_I2C_Regs, I2MASK3) == 0x3c, "struct LPC-I2C_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_PINCON_Regs, I2CPADCFG) == 0x7c, "struct LPC_PINCON_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_RIT_Regs, RICOUNTER) == 0xc, "struct LPC_RIT_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_RTC_Regs, ALYEAR) == 0x7c, "struct LPC_RTC_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_SC_Regs, DMAREQSEL) == 0x1c4, "struct LPC_SC_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_SSP_Regs, DMACR) == 0x24, "struct LPC_SSP_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_TIMER_Regs, CTCR) == 0x70, "struct LPC_Timer_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_UART0_Regs, TER) == 0x30, "struct LPC_UART0_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_UART1_Regs, RS485DLY) == 0x54, "struct LPC_UART1_Regs has incorrect size");

    _Static_assert(__builtin_offsetof(struct LPC_WDT_Regs, WDCLKSEL) == 0x10, "struct LPC_WDT_Regs has incorrect size");

    and in oder segment other error:

    #ifdef IEC_INPUTS_INVERTED
    static inline iec_bus_t iec_bus_read(void) {
    return (~IEC_INPUT) & (IEC_BIT_ATN | IEC_BIT_DATA | IEC_BIT_CLOCK | IEC_BIT_SRQ);
    }
    #else
    static inline iec_bus_t iec_bus_read(void) {
    return IEC_INPUT & (IEC_BIT_ATN | IEC_BIT_DATA | IEC_BIT_CLOCK | IEC_BIT_SRQ);
    }

    IEC_CLOCK

    lpc17xx/../iec-bus.h:45:68: error: 'IEC_BIT_SRQ' undeclared (first use in this function); did you mean 'IEC_BIT_ATN'?
    return IEC_INPUT & (IEC_BIT_ATN | IEC_BIT_DATA | IEC_BIT_CLOCK | IEC_BIT_SRQ);
    ^~~~~~~~~~~

    below link to 2 files:

    https://drive.google.com/file/d/1ISjmhER99hmYmDUjZKGDbAmklvLCtiOP/view?usp=sharing

    https://drive.google.com/file/d/1l5B-5R4kXiHXJX4gOlCXXSd28xxsqghL/view?usp=sharing

    all project MPLAB-X-IDE 6.2:

    https://drive.google.com/file/d/14uKaJd1aC3qTCfq9pkvF3Kfn6K6FZW-0/view?usp=sharing

Related