typedef struct in events file

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

typedef struct in events file

跳至解决方案
685 次查看
Albert_mtb
Contributor I

in the file main.c, i define

typedef struct
{
unsigned char A;
unsigned char B;
unsigned char C;
}TDATA_EXAMPLE;
TDATA_EXAMPLE Data_examples;

 

In the file events.c i want to modify a parameter of struct but i don't know how declare (extern ... ?)

 

Data_examples.A = 1;

 

0 项奖励
回复
1 解答
660 次查看
Alex_Wang
NXP Employee
NXP Employee

Hi, @Albert_mtb 

You can add the following code in event.c for external declaration:

typedef struct {
    unsigned char A;
    unsigned char B;
    unsigned char C;
} TDATA_EXAMPLE;
 
extern TDATA_EXAMPLE Data_examples;

You can also create a new header.h file to contain the TDATA_EXAMPLE struct definition by adding the following code to event.c:

#include "header.h"
 
extern TDATA_EXAMPLE Data_examples;

header.h is as follows:

#ifndef __HEADER_H
#define __HEADER_H
 
typedef struct {
    unsigned char A;
    unsigned char B;
    unsigned char C;
} TDATA_EXAMPLE;
 
#endif

I recommend using header file definitions for large projects.

Best regards, Alex

在原帖中查看解决方案

0 项奖励
回复
2 回复数
642 次查看
Albert_mtb
Contributor I

Thank you so much Alex

Best regards

661 次查看
Alex_Wang
NXP Employee
NXP Employee

Hi, @Albert_mtb 

You can add the following code in event.c for external declaration:

typedef struct {
    unsigned char A;
    unsigned char B;
    unsigned char C;
} TDATA_EXAMPLE;
 
extern TDATA_EXAMPLE Data_examples;

You can also create a new header.h file to contain the TDATA_EXAMPLE struct definition by adding the following code to event.c:

#include "header.h"
 
extern TDATA_EXAMPLE Data_examples;

header.h is as follows:

#ifndef __HEADER_H
#define __HEADER_H
 
typedef struct {
    unsigned char A;
    unsigned char B;
    unsigned char C;
} TDATA_EXAMPLE;
 
#endif

I recommend using header file definitions for large projects.

Best regards, Alex

0 项奖励
回复