I saw the following code provided by keil:
/* in cmsis_armclang.h */
...
#define __VECTOR_TABLE __Vectors
...
#define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section("RESET")))
...
/* in system_ARMCM3.h */
...
typedef void(*VECTOR_TABLE_Type)(void);
...
/* in startup_ARMCM3.c */
...
extern const VECTOR_TABLE_Type __VECTOR_TABLE[240];
const VECTOR_TABLE_Type __VECTOR_TABLE[240] __VECTOR_TABLE_ATTRIBUTE = {
(VECTOR_TABLE_Type)(&__INITIAL_SP), /* Initial Stack Pointer */
Reset_Handler, /* Reset Handler */
...
I don't understand why the __VECTOR_TABLE array needs to be declared with the extern keyword before it is defined.
When I remove the extern statement, a warning will appear during compilation.
RTE/Device/ARMCM3/startup_ARMCM3.c(80): warning: no previous extern declaration for non-static variable '__Vectors' [-Wmissing-variable-declarations]
const VECTOR_TABLE_Type __VECTOR_TABLE[240] __VECTOR_TABLE_ATTRIBUTE = {
^
D:/ProgramData/Arm/Packs/ARM/CMSIS/5.9.0/CMSIS/Core/Include/cmsis_armclang.h(128): note: expanded from macro '__VECTOR_TABLE'
#define __VECTOR_TABLE __Vectors
^
RTE/Device/ARMCM3/startup_ARMCM3.c(80): note: declare 'static' if the variable is not intended to be used outside of this translation unit
const VECTOR_TABLE_Type __VECTOR_TABLE[240] __VECTOR_TABLE_ATTRIBUTE = {
^
1 warning generated.