Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

typedef Structs pass by reference

typedef Structs pass by reference

2013-02-02 by englsprogeny1

Simple C question.. I guess that I am blowing!  Maybe I didn't get enough sleep last night....


Using AVR Studio 4.0 with GCC

1. I create a type that is a struct
2. I create multiple 'instances' of this type.


I get the following errors when I Build All:

menu.c:1729: error: expected declaration specifiers or '...' before 'offTimeStruct'
menu.c:1742: error: 'eventOff' undeclared (first use in this function)




typedef struct offTimeStruct
{
	uint8_t endMinute;
	uint8_t endHour;
};

offTimeStruct light1;
offTimeStruct rocket;



//menu.c: Line 1729
void CalculateOffTime(uint8_t duration, offTimeStruct &eventOff)
{
        //menu.c: Line 1742
	eventOff.endMinute = 1;

}




funtion call from Main()


CalculateOffTime(1, light1);

Thanks for your ideas guys!

Re: typedef Structs pass by reference

2013-02-02 by englsprogeny1

I've updated the struct, thanks.

I want to be able to update the values within the struct (depending on what 'instance' is passed into the function).

This is why I am doing 'pass by reference' (by the address)


I get the following error:

menu.c:1732: error: expected ';', ',' or ')' before '&' token

This is referring to the prototype portion of the function definition.

 

void CalculateOffTime(uint8_t duration, offTimeStruct &eventOff)



Any more ideas?



--- In AVR-Chat@yahoogroups.com, Charlie H  wrote:
Show quoted textHide quoted text
>
> It looks like you are expecting the address of the struct passed to your 
> function but not using the address in the function.  Try it this way:
> 
> void CalculateOffTime(uint8_t duration, offTimeStruct eventOff)
> {
>     ...
> }
> 
> 
> Also, I think the typedef is wrong.  Try it this way:
> 
> typedef struct
> {
> 	uint8_t endMinute;
> 	uint8_t endHour;
> } offTimeStruct;
> 
> 
> HTH,
> Charlie
> 
> 
> On 2/2/2013 2:51 PM, englsprogeny1 wrote:
> > Simple C question.. I guess that I am blowing!  Maybe I didn't get enough sleep last night....
> >
> >
> > Using AVR Studio 4.0 with GCC
> >
> > 1. I create a type that is a struct
> > 2. I create multiple 'instances' of this type.
> >
> >
> > I get the following errors when I Build All:
> >
> > menu.c:1729: error: expected declaration specifiers or '...' before 'offTimeStruct'
> > menu.c:1742: error: 'eventOff' undeclared (first use in this function)
> >
> >
> >
> >
> > typedef struct offTimeStruct
> > {
> > 	uint8_t endMinute;
> > 	uint8_t endHour;
> > };
> >
> > offTimeStruct light1;
> > offTimeStruct rocket;
> >
> >
> >
> > //menu.c: Line 1729
> > void CalculateOffTime(uint8_t duration, offTimeStruct &eventOff)
> > {
> >          //menu.c: Line 1742
> > 	eventOff.endMinute = 1;
> >
> > }
> >
> >
> >
> >
> > funtion call from Main()
> >
> >
> > CalculateOffTime(1, light1);
> >
> > Thanks for your ideas guys!
> >
> >
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>

Re: [AVR-Chat] typedef Structs pass by reference

2013-02-02 by Charlie H

It looks like you are expecting the address of the struct passed to your 
function but not using the address in the function.  Try it this way:

void CalculateOffTime(uint8_t duration, offTimeStruct eventOff)
{
    ...
}


Also, I think the typedef is wrong.  Try it this way:

typedef struct
{
	uint8_t endMinute;
	uint8_t endHour;
} offTimeStruct;


HTH,
Charlie
Show quoted textHide quoted text
On 2/2/2013 2:51 PM, englsprogeny1 wrote:
> Simple C question.. I guess that I am blowing!  Maybe I didn't get enough sleep last night....
>
>
> Using AVR Studio 4.0 with GCC
>
> 1. I create a type that is a struct
> 2. I create multiple 'instances' of this type.
>
>
> I get the following errors when I Build All:
>
> menu.c:1729: error: expected declaration specifiers or '...' before 'offTimeStruct'
> menu.c:1742: error: 'eventOff' undeclared (first use in this function)
>
>
>
>
> typedef struct offTimeStruct
> {
> 	uint8_t endMinute;
> 	uint8_t endHour;
> };
>
> offTimeStruct light1;
> offTimeStruct rocket;
>
>
>
> //menu.c: Line 1729
> void CalculateOffTime(uint8_t duration, offTimeStruct &eventOff)
> {
>          //menu.c: Line 1742
> 	eventOff.endMinute = 1;
>
> }
>
>
>
>
> funtion call from Main()
>
>
> CalculateOffTime(1, light1);
>
> Thanks for your ideas guys!
>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

Re: [AVR-Chat] typedef Structs pass by reference

2013-02-02 by Clark Martin

On Feb 2, 2013, at 11:51 AM, englsprogeny1 wrote:

> Simple C question.. I guess that I am blowing! Maybe I didn't get enough sleep last night....
> 
> Using AVR Studio 4.0 with GCC
> 
> 1. I create a type that is a struct
> 2. I create multiple 'instances' of this type.
> 
> I get the following errors when I Build All:
> 
> menu.c:1729: error: expected declaration specifiers or '...' before 'offTimeStruct'
> menu.c:1742: error: 'eventOff' undeclared (first use in this function)
> 
> typedef struct offTimeStruct
> {
> uint8_t endMinute;
> uint8_t endHour;
> };

As in another response the assigned label should go after the closing bracket

> 
> offTimeStruct light1;
> offTimeStruct rocket;
> 
> //menu.c: Line 1729
> void CalculateOffTime(uint8_t duration, offTimeStruct &eventOff)

You can pass either the struct (if it's small enough) or a pointer to the struct.  You can't do this, it has no meaning.

> void CalculateOffTime(uint8_t duration, offTimeStruct *eventOff)

> {
> //menu.c: Line 1742
> eventOff.endMinute = 1;

Since you are changing values in the struct you would need to pass (and use) a pointer to the struct...

> eventOff->endMinute = 1;


> 
> }
> 
> funtion call from Main()
> 
> CalculateOffTime(1, light1);

> CalculateOffTime(1, &light1);


&XXXXXX tells the compiler to pass the address of the data (struct)

*XXXXXX tells the compiler to access the data pointed to by the label.




[Non-text portions of this message have been removed]

Re: [AVR-Chat] Re: typedef Structs pass by reference

2013-02-02 by Charlie H

I agree with Clark on the pointer issue.  The & should be * in the 
function declaration.

Charlie
Show quoted textHide quoted text
On 2/2/2013 4:17 PM, englsprogeny1 wrote:
>
> I've updated the struct, thanks.
>
> I want to be able to update the values within the struct (depending on what 'instance' is passed into the function).
>
> This is why I am doing 'pass by reference' (by the address)
>
>
> I get the following error:
>
> menu.c:1732: error: expected ';', ',' or ')' before '&' token
>
> This is referring to the prototype portion of the function definition.
>
>   
>
> void CalculateOffTime(uint8_t duration, offTimeStruct &eventOff)
>
>
>
> Any more ideas?
>
>
>
> --- In AVR-Chat@yahoogroups.com, Charlie H  wrote:
>> It looks like you are expecting the address of the struct passed to your
>> function but not using the address in the function.  Try it this way:
>>
>> void CalculateOffTime(uint8_t duration, offTimeStruct eventOff)
>> {
>>      ...
>> }
>>
>>
>> Also, I think the typedef is wrong.  Try it this way:
>>
>> typedef struct
>> {
>> 	uint8_t endMinute;
>> 	uint8_t endHour;
>> } offTimeStruct;
>>
>>
>> HTH,
>> Charlie
>>
>>
>> On 2/2/2013 2:51 PM, englsprogeny1 wrote:
>>> Simple C question.. I guess that I am blowing!  Maybe I didn't get enough sleep last night....
>>>
>>>
>>> Using AVR Studio 4.0 with GCC
>>>
>>> 1. I create a type that is a struct
>>> 2. I create multiple 'instances' of this type.
>>>
>>>
>>> I get the following errors when I Build All:
>>>
>>> menu.c:1729: error: expected declaration specifiers or '...' before 'offTimeStruct'
>>> menu.c:1742: error: 'eventOff' undeclared (first use in this function)
>>>
>>>
>>>
>>>
>>> typedef struct offTimeStruct
>>> {
>>> 	uint8_t endMinute;
>>> 	uint8_t endHour;
>>> };
>>>
>>> offTimeStruct light1;
>>> offTimeStruct rocket;
>>>
>>>
>>>
>>> //menu.c: Line 1729
>>> void CalculateOffTime(uint8_t duration, offTimeStruct &eventOff)
>>> {
>>>           //menu.c: Line 1742
>>> 	eventOff.endMinute = 1;
>>>
>>> }
>>>
>>>
>>>
>>>
>>> funtion call from Main()
>>>
>>>
>>> CalculateOffTime(1, light1);
>>>
>>> Thanks for your ideas guys!
>>>
>>>
>>>
>>>
>>>
>>> ------------------------------------
>>>
>>> Yahoo! Groups Links
>>>
>>>
>>>
>>>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

Re: [AVR-Chat] Re: typedef Structs pass by reference

2013-02-02 by Martin McKee

Pass-by-reference is only available in C++.  In C you have to pass in a
pointer, and, for that, you use * as has been mentioned.

 void CalculateOffTime( uint8_t duration, offTimeStruct* eventOff )

then, eventOff->endMinute = ...

Martin Jay McKee

On Sat, Feb 2, 2013 at 2:22 PM, Charlie H <carlosh1@twcny.rr.com> wrote:

> **
>
>
> I agree with Clark on the pointer issue. The & should be * in the
> function declaration.
>
> Charlie
>
>
> On 2/2/2013 4:17 PM, englsprogeny1 wrote:
> >
> > I've updated the struct, thanks.
> >
> > I want to be able to update the values within the struct (depending on
> what 'instance' is passed into the function).
> >
> > This is why I am doing 'pass by reference' (by the address)
> >
> >
> > I get the following error:
> >
> > menu.c:1732: error: expected ';', ',' or ')' before '&' token
> >
> > This is referring to the prototype portion of the function definition.
> >
> >
> >
> > void CalculateOffTime(uint8_t duration, offTimeStruct &eventOff)
> >
> >
> >
> > Any more ideas?
> >
> >
> >
> > --- In AVR-Chat@yahoogroups.com, Charlie H wrote:
> >> It looks like you are expecting the address of the struct passed to your
> >> function but not using the address in the function. Try it this way:
> >>
> >> void CalculateOffTime(uint8_t duration, offTimeStruct eventOff)
> >> {
> >> ...
> >> }
> >>
> >>
> >> Also, I think the typedef is wrong. Try it this way:
> >>
> >> typedef struct
> >> {
> >> uint8_t endMinute;
> >> uint8_t endHour;
> >> } offTimeStruct;
> >>
> >>
> >> HTH,
> >> Charlie
> >>
> >>
> >> On 2/2/2013 2:51 PM, englsprogeny1 wrote:
> >>> Simple C question.. I guess that I am blowing! Maybe I didn't get
> enough sleep last night....
> >>>
> >>>
> >>> Using AVR Studio 4.0 with GCC
> >>>
> >>> 1. I create a type that is a struct
> >>> 2. I create multiple 'instances' of this type.
> >>>
> >>>
> >>> I get the following errors when I Build All:
> >>>
> >>> menu.c:1729: error: expected declaration specifiers or '...' before
> 'offTimeStruct'
> >>> menu.c:1742: error: 'eventOff' undeclared (first use in this function)
> >>>
> >>>
> >>>
> >>>
> >>> typedef struct offTimeStruct
> >>> {
> >>> uint8_t endMinute;
> >>> uint8_t endHour;
> >>> };
> >>>
> >>> offTimeStruct light1;
> >>> offTimeStruct rocket;
> >>>
> >>>
> >>>
> >>> //menu.c: Line 1729
> >>> void CalculateOffTime(uint8_t duration, offTimeStruct &eventOff)
> >>> {
> >>> //menu.c: Line 1742
> >>> eventOff.endMinute = 1;
> >>>
> >>> }
> >>>
> >>>
> >>>
> >>>
> >>> funtion call from Main()
> >>>
> >>>
> >>> CalculateOffTime(1, light1);
> >>>
> >>> Thanks for your ideas guys!
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> ------------------------------------
> >>>
> >>> Yahoo! Groups Links
> >>>
> >>>
> >>>
> >>>
> >
> >
> >
> > ------------------------------------
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
>
>  
>


[Non-text portions of this message have been removed]

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.