typedef struct in events file

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

typedef struct in events file

Jump to solution
421 Views
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 Kudos
1 Solution
396 Views
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

View solution in original post

0 Kudos
2 Replies
378 Views
Albert_mtb
Contributor I

Thank you so much Alex

Best regards

397 Views
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 Kudos