typedef struct in events file

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

typedef struct in events file

ソリューションへジャンプ
509件の閲覧回数
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 解決策
484件の閲覧回数
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 返答(返信)
466件の閲覧回数
Albert_mtb
Contributor I

Thank you so much Alex

Best regards

485件の閲覧回数
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 件の賞賛
返信