Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] problems with pointer to struct

Status
Not open for further replies.

AliBahar

Member level 2
Member level 2
Joined
Feb 4, 2015
Messages
42
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
337
Hi every one. I have typical structure (ECU_t) which has members that considered to be pointer to struct.
i make my question in c code comments. please help me. by the way i have used freescale code warrior as compiler.
Code:
typedef enum
{
	NORMAL,
	WARNING,
}WATER_TEMP;

typedef struct
{
	WATER_TEMP water_temp;
	uint16_t speed;
	// ... other members
}Engine_t;

typedef struct
{
	Engine_t* engine;
	ABS_t*  abs;
	// ... other members
}ECU_t;

void ECU_DoTask(ECU_t* output)
{
	output->engine->water_temp = NORMAL; 
	
}

void main ()
{
	ECU_t ecu;
	ECU_DoTask(&ecu);
	// i want to access to water_temp. how can i do it?
	// if i use (ecu.engine->water_temp) there is no value (NORMAL) in variable.
	while(1);
}
 

Easyrider83

Advanced Member level 5
Advanced Member level 5
Joined
Oct 11, 2011
Messages
1,608
Helped
374
Reputation
748
Reaction score
362
Trophy points
1,363
Location
Tallinn, Estonia
Activity points
8,575
ECU_t ecu; - is your local structure
ABS_t* abs; - is just a pointer having zero value or junk in the beggining

ABS_t _abs; - you should declare structure and then attach it to main structure

ecu.abs = &_abs;

or like this:
ECU_t ecu = { .abs = &_abs };
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top