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

'extern' keyword for an array

In file AAA.c

const char CMD_Fire[] = "FIRE";

In file BBB.c

extern const char CMD_Fire[];

It seems that, the compiler is not able to know the size of CMD_Fire[], when compiling BBB.c

So, I have to hard code the size of CMD_Fire[] in BBB.c

Then, if I change the command to "Fire it!", I will need to change the size of CMD_Fire[] everywhere.

Is there any skill to handle this?

Parents
  • Thanks for all the replies.

    Many thanks to Andy's helps and the very good examples.

    I know that I still lack a lot of fundamental knowledge; sorry for that.

    If I do this globally:

    extern const char TEST_COMMAND[];
    const char TEST_COMMAND[] = "TEST";
    

    It is OK.

    If I do this locally:

    void CMD_Handle(void)
    {
        extern const char TEST_COMMAND[];
        const char TEST_COMMAND[] = "TEST";    // Line 517
    
        UART3sbWRITE( (BYTE *)TEST_COMMAND, 4 );
        UART3sendKICK();
    }
    

    I get the error.

    source\RS485.c(517): error:  #101: "TEST_COMMAND" has already been declared in the current scope
    

    I think that, I don't really understand "extern". I am confused.

Reply
  • Thanks for all the replies.

    Many thanks to Andy's helps and the very good examples.

    I know that I still lack a lot of fundamental knowledge; sorry for that.

    If I do this globally:

    extern const char TEST_COMMAND[];
    const char TEST_COMMAND[] = "TEST";
    

    It is OK.

    If I do this locally:

    void CMD_Handle(void)
    {
        extern const char TEST_COMMAND[];
        const char TEST_COMMAND[] = "TEST";    // Line 517
    
        UART3sbWRITE( (BYTE *)TEST_COMMAND, 4 );
        UART3sendKICK();
    }
    

    I get the error.

    source\RS485.c(517): error:  #101: "TEST_COMMAND" has already been declared in the current scope
    

    I think that, I don't really understand "extern". I am confused.

Children