![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Null Object not de-referenced properly by interpreter Topic Summary: Created On: 19-Nov-2008 19:36 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
Folks,
If you run the attached code from an open module, you will see that test2() does not properly catch when the object passed in is null. The function should catch when the object passed in is null. |
|
![]() |
|
![]() |
|
I've seen behavior similar to this when a function tries to use a parameter defined for output with the & character. Its been explained to me but I really don't understand why. Its a clear problem with DXL and, I believe, some other languages. I've been forced to accumulate the desired output parameters in temporary variables, then set the output paramaters at the end of the function.
Anyway, I notice your function works when you delete the ampersand &. I also notice that it works if you define "Object o1 = 0" and then test o1 in your function. If you do that and then call test2 twice in a row, you get the error message only once, which is correct. See attached. This reminds me of that old saying: "Give me the courage to change what I can, the Serenity to accept what I cannot, and the Wisdom to tell the difference". In this case Wisdom says you cannot change it, so get some Serenity then modify your functions to accomodate this reality. - Louie PS. That saying comes to mind a lot when using DXL... |
|
![]() |
|
![]() |
|
Louie,
That is one way to work around the problem. Thanks for the input. The problem is that the interpreter does not de-reference the object properly (Only when it's null)..all other cases the interpreter does what one would expect it to do. |
|
![]() |
|
![]() |
|
DXL automatically passes DXL specific types by reference anyway.
------------------------- David Pechacek AAI Services Textron dpechacek@sc-aaicorp.com David.Pechacek@gmail.com |
|
![]() |
|
![]() |
|
David,
That is exactly what I thought but if you look at the code below you will see that is really not the case. If the Object is supposed to be passed by reference then the current object should be set. |
|
![]() |
|
![]() |
|
Hi Douglas, David, Louie,
I think the confusion about when to pass by reference arrises from different semantics of the same syntax depending on the variable type. At least, I found that my intuition leads me right most of the time. string s = "some text" // "some text" is placed in the string table, and pointer s is assigned that address. s = "other nonsense" // "more nonsense" is placed in the string table, and pointer s is assigned the new address. Buffer b = create // reserve some memory b = "some text" // assign text to memory b = "more nonsense" // assign different text to memory ==> DXL first creates a memory area for the buffer, then assigns its address to pointer b, finally we write "some text" into that area. (Memory management takes care to extend the area when needed.) Thus, if I want to replace "some text" with "more nonsense", in the first example, I need to change the pointer, because, as a string my "more nonsense" will be at a different address. In the Buffer example, I overwrite "some text" at the same address. For this reason, you usually don't need to pass a Buffer by reference. (There may be cases when you do actually want to shuffle the association of memory areas and variables, e.g. you could have two Buffer variables pointing at the same buffer memory.) I know from experience that this works for Buffers and Skip lists. I've not worked with DxlObjects in the same way yet. For the type Object, certainly the string example applies. The objects are at fixed addresses in memory and only the pointers are changed. Still the issue with the null test is annoying, I have to agree. It has hit me several times when I was working with OLE objects. Cheers, Malte PS: Code&Comments may be easier to read here: |
|
![]() |
|
![]() |
|
Perhaps it's passed as a constant reference?
|
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.