Another Pass-by-reference bug?
Author |
Message |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Another Pass-by-reference bug?
If you run the above code, the LCD will give you the following output: smFlags was initialized to 0x100 in SMStart(), so "Before=100" is correct. However, when SMClearAllEvents() is called, the smFlags referenced became zero "ClearEvt:0". That's wrong. Then when SMClearAllEvents() returned, the smFlags remained zero "After=0". If I commented out the global variable "int g_data[2]", the output became: If I commented out the for-loop or any lines in the for-loop in SMClearAllEvents(), the output became: I am using RobotC 3.03, the latest. Can you confirm this is indeed a bug in the compiler? If so, can this be fixed or worked around? Thanks.
|
Tue Sep 27, 2011 7:57 am |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Another Pass-by-reference bug?
After reviewing a similar bug I found last year, I suspect this is the same thing. But Dick told me he had fixed it in ver 2.32. The symptom is very similar to the previous bug report where I passed the structure reference more than one function deep (i.e. the sm structure was passed by reference to the function SMStart which in turn passed it to SMClearAllEvents). viewtopic.php?f=52&t=2712&hilit=RobotC+bug+concerning+structures
|
Tue Sep 27, 2011 2:21 pm |
|
 |
tfriez
Site Admin
Joined: Wed Jan 24, 2007 10:42 am Posts: 620
|
 Re: Another Pass-by-reference bug?
We're looking into this issue right now. Thanks for reporting!
_________________Timothy Friez ROBOTC Developer - SW Engineer tfriez@robotc.net
|
Tue Sep 27, 2011 4:41 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Another Pass-by-reference bug?
Any progress on this issue? Is the issue confirmed? If so, is there a fix or work around that I can try? Thanks.
|
Thu Sep 29, 2011 11:05 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Another Pass-by-reference bug?
I have been playing with the code and found it is definitely an issue with trying to pass a structure by reference to another function if the structure itself was pass to it by reference. It seems the compiler did not compute the pointer correctly when it is passing it to the second function. This is exactly the same bug I found last year and Dick said it was fixed. If I changed my code to the following, it will fix the issue. Basically, I had to declare a second structure within the first function, copy the structure to the new structure and pass the new structure by reference to the second function. After calling the second function, then copy the new structure content back to the old structure before returning. BTW, am I supposed to be able to copy a structure by assigning the old structure to the new structure (e.g. sm01 = sm02)? If so, that is another bug, structure assignment doesn't work. See the sm01 and sm02 assignment in the code below.  |  |  |  | Code: #define MAX_WAIT_EVENTS 4 #define SMF_READY 0x0100 #define SMF_TIMEOUT 0x0200
typedef struct { int evtType; int evtID; int evtData; int evtParam1; int evtParam2; bool fSignaled; } WAIT_EVT;
typedef struct { int currState; int nextState; long timeout; int smFlags; int nWaitEvents; WAIT_EVT WaitEvents[MAX_WAIT_EVENTS]; } SM;
int g_data[2]; SM g_AutoSM; SM sm01, sm02;
void SMClearAllEvents(SM &sm) { nxtDisplayTextLine(1, "ClearEvt:%x", sm.smFlags); for (int i = 0; i < MAX_WAIT_EVENTS; ++i) { sm.WaitEvents[i].evtType = 0; sm.WaitEvents[i].evtID = 0; sm.WaitEvents[i].evtData = 0; sm.WaitEvents[i].evtParam1 = 0; sm.WaitEvents[i].evtParam2 = 0; sm.WaitEvents[i].fSignaled = false; } sm.nWaitEvents = 0; sm.timeout = 0; sm.smFlags &= ~SMF_TIMEOUT; } //SMClearAllEvents
void SMInit(SM &sm) { sm.currState = 0; sm.nextState = 0; sm.smFlags = 0; } //SMInit
void SMStart(SM &sm) { SM sm2; if (sm.currState == 0) { sm.currState = 1; sm.nextState = 1; sm.smFlags = 0x3FFF; nxtDisplayTextLine(0, "Before=%x", sm.smFlags); sm2.smFlags = sm.smFlags; SMClearAllEvents(sm2); sm.smFlags = sm2.smFlags; nxtDisplayTextLine(2, "After=%x", sm.smFlags); } } //SMStart
task main() { sm01.smFlags = 0x1234; sm02.smFlags = 0x4321; sm01 = sm02; nxtDisplayTextLine(4, "1=%x,2=%x", sm01.smFlags, sm02.smFlags); SMInit(g_AutoSM); SMStart(g_AutoSM); nxtDisplayTextLine(3, "D0=%x,D1=%x", g_data[0], g_data[1]); } //main
|  |  |  |  |
|
Fri Sep 30, 2011 12:40 am |
|
 |
tfriez
Site Admin
Joined: Wed Jan 24, 2007 10:42 am Posts: 620
|
 Re: Another Pass-by-reference bug?
We hope to have the fix available sometime next week. I'm sorry I can't give you any more assistance then that other than we have confirmed the issue and are working on fixing it.
Thanks.
_________________Timothy Friez ROBOTC Developer - SW Engineer tfriez@robotc.net
|
Fri Sep 30, 2011 2:29 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Another Pass-by-reference bug?
Thanks for the info. In that case, I will wait for the fix and won't try to work around it.
|
Fri Sep 30, 2011 2:36 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Another Pass-by-reference bug?
Any update on this issue? In particular, is there an ETA on this fix? Thanks.
|
Wed Oct 05, 2011 6:47 pm |
|
 |
tfriez
Site Admin
Joined: Wed Jan 24, 2007 10:42 am Posts: 620
|
 Re: Another Pass-by-reference bug?
We'll be issuing a fix for this bug (and a few others) by end of day today.
Thanks.
_________________Timothy Friez ROBOTC Developer - SW Engineer tfriez@robotc.net
|
Mon Oct 10, 2011 9:17 am |
|
 |
tfriez
Site Admin
Joined: Wed Jan 24, 2007 10:42 am Posts: 620
|
 Re: Another Pass-by-reference bug?
This is now fixed in 3.04, which is available now.
_________________Timothy Friez ROBOTC Developer - SW Engineer tfriez@robotc.net
|
Mon Oct 10, 2011 4:16 pm |
|
 |
nateww
Rookie
Joined: Fri Apr 15, 2011 10:29 am Posts: 37
|
 Re: Another Pass-by-reference bug?
Would love to see the release notes for 3.04 if wouldn't mind. 
|
Mon Oct 10, 2011 8:50 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Another Pass-by-reference bug?
I second that. Would love to see what's been fixed in 3.04.
|
Mon Oct 10, 2011 8:59 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: Another Pass-by-reference bug?
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Tue Oct 11, 2011 2:01 am |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Another Pass-by-reference bug?
Is structure assignment supposed to work? I tested the above code with the new 3.04 and it still not working.
|
Tue Oct 11, 2011 3:18 am |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: Another Pass-by-reference bug?
Do you have a complete program to demonstrate this?
Edit: I tend to use memcpy() for copying structs from one to the other.
- Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Tue Oct 11, 2011 4:39 am |
|
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|