Re: Dhrystone compiled on BBQL with Digital C SE
Posted: Mon Aug 08, 2022 10:21 pm
Ok, given this table...things in {} are each element's value. The number at the top is the record struct's address. The first element of each struct (PtrComp) takes on that address, the next element (Discr) would have an offset of address+4 since the first element (PtrComp) is a 4-byte address.
Articulating my understanding verbally so you can correct me if I'm wrong:
When you do PtrParIn->PtrComp->PtrComp you are getting value 300. When you de-reference it (via &) you should be getting address 200 since the de-reference operator asks for the address instead of the value of that variable. Thus you are able to change its value (by re-referencing it via *) from 300 to some other value, i.e. *200 says go to address 200 and change the value contained at that address
(Note that *200 is not valid C syntax since you obviously never put * in front of a literal numeric address, you'd put it in front of a variable containing that address...I just did that to demonstrate my point...for those that haven't seen how de-reference/re-reference works in C, look at the last code snippet that shows how it's used.)
Similarly
If this is correct then it would seem version 1.1 of Dhyrstone had a bug since it does this:
Whereas version 2.0 of Dhrystone does this (note the & in the Proc3 function call):
Code: Select all
a) b) c)
+->100 +->200 +->300
| | |
PtrParIn{100}----+ PtrComp{200}----+ PtrComp{300}----+ PtrComp{null}
Discr{0} Discr{0} Discr{0}
EnumComp{0} EnumComp{0} EnumComp{0}
... ... ...
When you do PtrParIn->PtrComp->PtrComp you are getting value 300. When you de-reference it (via &) you should be getting address 200 since the de-reference operator asks for the address instead of the value of that variable. Thus you are able to change its value (by re-referencing it via *) from 300 to some other value, i.e. *200 says go to address 200 and change the value contained at that address
(Note that *200 is not valid C syntax since you obviously never put * in front of a literal numeric address, you'd put it in front of a variable containing that address...I just did that to demonstrate my point...for those that haven't seen how de-reference/re-reference works in C, look at the last code snippet that shows how it's used.)
Code: Select all
addr1 = PtrParIn->PtrComp; /* addr1 equals 200 */
addr2 = PtrParIn->PtrComp->PtrComp; /* addr2 equals 300 */
addr3 = &PtrParIn->PtrComp->PtrComp; /* addr2 equals 200 since you are asking for address of who's pointing to it */
Code: Select all
NextRecord = PtrParIn->PtrComp;
addr1 = NextRecord; /* addr1 equals 200 */
addr2 = NextRecord->PtrComp; /* addr2 equals 300 */
addr3 = &NextRecord->PtrComp; /* addr3 equals 200 again */
Code: Select all
Proc3(PtrParIn->PtrComp->PtrComp);
...
Proc3(PtrParOut)
RecordPtr * PtrParOut;
{
*PtrParOut = 400; /* this would change what is at address 300 */
}
Code: Select all
NextRecord = PtrParIn->PtrComp;
Proc3(&NextRecord->PtrComp);
...
Proc3(PtrParOut)
RecordPtr * PtrParOut;
{
*PtrParOut = 400; /* this would change what is at address 200 */
}