I am trying to study a code which I havent written.
In the below code a struct ICB_CMD_ is defined, and then *ICB_PCMD , is ICB_PCMD pointer to ICB_CMD_ ??
typedef struct ICB_CMD_
UINT8 au8Data[BUFFER_LENGTH-5]; //5: ENQ/ACK/NAK ID #BYTES CRCH CRCL BUFFER_LENGTH=200
EXTERN ICB_PCMD icb_pRxCmd;
EXTERN ICB_PCMD icb_pTxCmd;
What does the below 2 lines do ?
The "extern" keyword allows you to access variables declared in another source file.
Here's some useful reading material on the subject:
StackOverflow - How do I use extern to share variables between source files in C?
StackOverflow - How to correctly use the extern keyword in C
Understanding “extern” keyword in C
In the code above
*ICB_PCMD is a pointer type to a type of
struct ICB_CMD_, and it's not initialized yet.
extern makes a variable visible in other source modules.
In this code both way of declaration can be used:
struct ICB_CMD_ *var2;
Both pointers :
extern ICB_PCMD icb_pRxCmd;
exterb ICB_PCMD icb_pTxCmd;
are external, which means they are declared in other file(s) but now (with
extern) are accessible in the current source module.