This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Warning if type mismatch

I have one file in which I use "int16_t x", when I declared it in other file, by mistake I have declared "extern int8_t x". i.e int8_t is used instead of int16_t.

But compiler do not generate warning for this. Why.
Is there any method for it or it has to be taken care by the programmer only.

Parents
  • How could it?

    Remember that the compiler only "sees" one compilation unit (usually, one .c file and all its #includes) at a time - it has absolutely no knowledge whatsoever of anything else.

    The only way that the compiler knows about external symbols is through the information that you provide in extern declarations - so it's up to you to ensure that they are correct!

    A common way to do this is to have:

    file1.h

    extern int16_t x;
    

    file1.c

    #include "file1.h"
    
    int16_t x;
    

    Then, when it compiles file1.c, the compiler does see both the extern declaration and the definition of x - and can give a warning if they don't match!

    This is standard, basic 'C' - nothing specifically to do with Keil or ARM.

    c-faq.com/.../decldef.html

Reply
  • How could it?

    Remember that the compiler only "sees" one compilation unit (usually, one .c file and all its #includes) at a time - it has absolutely no knowledge whatsoever of anything else.

    The only way that the compiler knows about external symbols is through the information that you provide in extern declarations - so it's up to you to ensure that they are correct!

    A common way to do this is to have:

    file1.h

    extern int16_t x;
    

    file1.c

    #include "file1.h"
    
    int16_t x;
    

    Then, when it compiles file1.c, the compiler does see both the extern declaration and the definition of x - and can give a warning if they don't match!

    This is standard, basic 'C' - nothing specifically to do with Keil or ARM.

    c-faq.com/.../decldef.html

Children