- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Why I write code creator 2.0, there will be two different situations
I wrote
{
commTxBuffer [4 + dptr + dptr] = modbusRAM [commRxBuffer [3] + dptr ++];
}
And writing
{
commTxBuffer [4 + dptr + dptr] = modbusRAM [commRxBuffer [3] + dptr];
dptr ++;
}
Will get different results?
(Translation on google translate)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1. NEVER have a vaiable on the left side changed on the right side
your dptr is modified on the right side, so when saving the value, it would used the CHANGED dptr
In your second example, your dptr doesn't change on the first line, it was incremented in the 2nd line, after the write instruction
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I also would not use dptr as dptr should be a reserved name in PSOC3 which is a 8051 core.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The basic principle here is that the expression on the right hand side of "=" is evaluated before the one on the left. So the pointer is incremented before being used in the assignment.
-Kenny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem is that in C it is not defined what evaluation has to be done first, the address of the result (LValue) or the expression at the right hand side of the equal sign. So a change of / in the compiler could induce a completely different behaveour. A nightmare for every programmer!
Have a look here http://publications.gbdirect.co.uk/c_book/chapter8/sequence_points.html at "Sequence Points" and see, that exactly the problem you have got is mentioned: NEVER use constructs like
a{i] = i++;
Happy coding
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I use Designer writing
{
commTxBuffer [4 + dptr + dptr] = modbusRAM [commRxBuffer [3] + dptr ++];
}
Will be equal to Create 2.0
{
commTxBuffer [4 + dptr + dptr] = modbusRAM [commRxBuffer [3] + dptr];
dptr + +;
}
(Translation on google translate)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It would be better to use the second method.
Don't use the first one.
It is a general pratise for any compiler or IDE.