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

how to define external a const array ?

Hi All,

I have an array struct's with const data in flash memory defined as follows

   const SOD_ObjectDictionaryEntry* pSDOEntryTable = SDOEntryTable;

This works fine ...

I want to use this array in an external file as follows

   extern const SOD_ObjectDictionaryEntry SDOEntryTable[];

Compiling give me following error : error: #513: a value of type "const SOD_ObjectDictionaryEntry *" cannot be assigned to an entity of type "SOD_ObjectDictionaryEntry *".

when I replace it by

   extern const SOD_ObjectDictionaryEntry* SDOEntryTable;


I have the same error.

extern SOD_ObjectDictionaryEntry SDOEntryTable[]


the linker gives an error SDOEntryTable not found , witch is normal.

How can I define a pointer to const data external ?

Thanks

Parents
  • const SOD_ObjectDictionaryEntry* pSDOEntryTable = SDOEntryTable;
    

    This defines a pointer to SDOEntryTable, not an array. Presumably, SDOEntryTable is an array. You didn't show the definition of SDOEntryTable. Is there a reason why you are defining a pointer instead of using the array identifier directly?
    So you have two variables: an array and a pointer. Do you want the pointer to be used in multiple source files? If so, declare it in the other files like so:

    extern const SOD_ObjectDictionaryEntry* pSDOEntryTable;
    


    The simple rule is this: a declaration without the extern keyword defines a variables (and allocates memory for it), whereas a declaration with the extern keyword simply creates a reference to a variable defined in another file.

Reply
  • const SOD_ObjectDictionaryEntry* pSDOEntryTable = SDOEntryTable;
    

    This defines a pointer to SDOEntryTable, not an array. Presumably, SDOEntryTable is an array. You didn't show the definition of SDOEntryTable. Is there a reason why you are defining a pointer instead of using the array identifier directly?
    So you have two variables: an array and a pointer. Do you want the pointer to be used in multiple source files? If so, declare it in the other files like so:

    extern const SOD_ObjectDictionaryEntry* pSDOEntryTable;
    


    The simple rule is this: a declaration without the extern keyword defines a variables (and allocates memory for it), whereas a declaration with the extern keyword simply creates a reference to a variable defined in another file.

Children