Clang intellisense is not recognising bool correctly

Sysprogs forums Forums VisualGDB Clang intellisense is not recognising bool correctly

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #37126
    wtywtykk
    Participant

    Hi,

    I’m having issue with the intellisense. It’s showing underlines on bool/true/false, saying “Use of undeclared identifier bool”. But the file can actually compile.

    I think the problem may be some version discrepancy. In stdbool.h, it’s not declaring the type because it thinks it should be keywords, while clang doesn’t think so:

    #if defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L
    /* bool, true and false are keywords. */
    #else
    #define bool _Bool
    #define true 1
    #define false 0
    #endif

    Example code to reproduce: Note the extension of the file is .c, not cpp.

    The GCC tool chain version is 15.2.1/15.2/r1

     

    #include

    int main(void)
    {
    bool aaa = false;

    return 0;
    }

     

    cmake_minimum_required(VERSION 3.15)

    project(EmbeddedProject1_bool LANGUAGES C CXX ASM)

    find_bsp(
    ID com.sysprogs.arm.stm32f4
    VERSION 1.28.0
    MCU STM32F407VE
    FRAMEWORKS com.sysprogs.arm.stm32.hal com.sysprogs.arm.stm32.ll
    HWREGISTER_LIST_FILE STM32F4xxxx/DeviceDefinitions/stm32f407xx.xml
    DISABLE_GNU_EXTENSIONS)

    add_bsp_based_executable(
    NAME EmbeddedProject1_bool
    SOURCES EmbeddedProject1_bool.c system_stm32f4xx.c stm32f4xx_hal_conf.h
    GENERATE_BIN
    GENERATE_MAP
    OUTPUT_RELOCATION_RECORDS)

     

    Is there any way to fix that?

     

    Regards,

    Tianyi

    • This topic was modified 1 month ago by wtywtykk.
    #37128
    support
    Keymaster

    Hi,

    This happens due to different default language standards between GCC/Clang. The easiest way to fix it is to explicitly select the C23 language standard in the project properties.

    For CMake, that would be Target properties -> C/C++ -> Advanced -> Language Standard for C files -> C23, or directly in CMakeLists.txt:

    set_property(TARGET EmbeddedProject1_bool PROPERTY C_STANDARD 23)
    #37129
    wtywtykk
    Participant

    Thanks, it works!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.