Reply To: Returning strings from C functions

homepage Forums BridgePoint/xtUML Usage and Training Returning strings from C functions Reply To: Returning strings from C functions

#2444
cort
Keymaster

The MC-3020 model compiler translates the above OAL into C.

C does not have a native string type, so returning strings from functions provides challenges. Namely, a pointer can be returned, but data itself exists “behind the pointer”. This is usually O.K.

However, consider the operations scmp and simple above. What if the strings returned were local variables formed and calculated inside the scope of the respective functions?

In such a case, the return pointer will point to deallocated stack space. This is not good.

To address this, an analysis has been performed outlining options for changing the MC-3020 model compiler. The analysis is documented here.

https://github.com/cortlandstarrett/bridgepoint/blob/master/doc-bridgepoint/notes/589_stringtest/586_stringtest.ant.md

Please read the above note and provide your thoughts here.