Chapter 10: C Structures
truct pwm widestPWM(struct pwm pulser1, struct pwm pulser2,
if (pulser1.width > pulser3.width) return pulser1;
/ Declare a function with struct pointers as parameters
destPWM(struct pwm *, struct pwm *, struct pwm *);
re we use the structure pointer operator ‘->’ to access members of the struct
ces stumble all over using the structure member operator
d.
wm pulser4k10;
truct pwm myWidestPWM;
10;
s
struct pwm pulser2,)
{
if(pulser1.width > pulser2.width)
{
}
else if (pulser2.width > pulser3.width) return pulser2
return pulser3;
}
But that’s one big memory hog. We can save stack memory by defining a function
to use struct pointers as paramerters:
/
struct pwm wi
// Define it
struct pwm widestPWM(struct pwm p1, struct pwm p2, struct pwm *p2)
{
if(p1.width > p2.width)
{
if (p1->width > p3->width) return p1;
}
else if (p2->width > p->width) return p2
return p3;
}
He
passed by a pointer. Novi
‘.’ and the structure pointer operator ‘->’ operator, so be forewarne
We use this function as follows:
struct pwm pulser1k50;
struct pwm pulser1k25;
struct p
s
myWidestPWM = widestPWM(&pulser1k50, &pulser1k25, &pulser4k