当前位置: 动力学知识库 > 问答 > 编程问答 >

Pointer to Structure

问题描述:

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 u8MsgId;

UINT8 u8Addr;

UINT8 u8Length;

UINT8 u8MainCmd;

UINT8 u8SubCmd;

UINT8 au8Data[BUFFER_LENGTH-5]; //5: ENQ/ACK/NAK ID #BYTES CRCH CRCL BUFFER_LENGTH=200

}*ICB_PCMD;

also then

EXTERN ICB_PCMD icb_pRxCmd;

EXTERN ICB_PCMD icb_pTxCmd;

What does the below 2 lines do ?

Many Thanks.

网友答案:

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.

The extern makes a variable visible in other source modules.

In this code both way of declaration can be used:

struct ICB_CMD_ *var2;

or

ICB_PCMD var3;

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: