Search code examples
cmicrocontrollerkeil

Keil Compiler Warning: anonymous unions are a c11 extension [-wc11-extensions]?


(Edited) Trying to compile a microcontroller program and have in a page of C code some 44 warnings of this type. Since no lines are flagged in my C file, I assume some sort of problem in an included header file. I have no clue what this warning even means or how it might affect my programs running. Here is the complete warning message:

C:/Users/Binky/AppData/Local/Arm/Packs/Keil/TM4C_DFP/1.1.0/Device/Include/TM4C123\TM4C123GH6PM.h(1251): warning: anonymous unions are a C11 extension [-Wc11-extensions]

That '1251' number gets changed for each warning posted.

I haven't tried anything except Googling the error and not getting anything comprehensible in the way of hits, which were only about 4.I do not know what else I can do if I don't understand what this warning means.

2nd Edit: Although I could not find the file path in explorer - for reasons unknown, there is no AppData after Binky, unless I do a search box query - I came up with the line by just clicking on the warning line in Keil. It brings me to a Union, a new one for each warning.


Solution

  • The error message includes the path and file name of the source file triggering the error:

    C:/Users/Binky/AppData/Local/Arm/Packs/Keil/TM4C_DFP/1.1.0/Device/Include/TM4C123\TM4C123GH6PM.h
    

    You will not and you should not change such a file, because it belongs to your installation of Keil. It it were one of your own files, you would change it, though.

    Instead, add the option -Wno-c11-extensions to the compiler call. Visit the preferences of your project for this.

    Alternatively you can adjust the version of the C standard, if the preferences allow you. For GCC this is the option -std=c11, you might want to research for newer versions. Apparently the chosen standard for your project is pre-C11.


    Background:

    The C standard changes certain details between its releases. Before C11 (as of 2011) anonymous unions are not compliant.

    The following table summarizes what an anonymous union looks like, shamelessly copied from this answer:

    Code Anonymous union Reason
    union { int x; }; YES Has no identifier and no tag
    union a { int x; }; NO Has an identifier a
    union { int x; } b; NO Has a tag b
    union a { int x; } b; NO Has an identifier a and tag b