Hi,
This is similar to the assert construct in C. This is not a bad idea. Could one not overload the TTCN-3 exception concept so that
it applies to both procedure and message based communication or exceptions occurring during test execution. (division by zero,
over/underflow, etc.) could be trapped as in other languages.
The additional code may obfuscate the intent or purpose of some piece of code, but it is useful. I am in favour of adding this
to the standard.
Cheers,
Claude.
Original Message
From: Mariusz Kupiec [
This email address is being protected from spambots. You need JavaScript enabled to view it.]
Sent: 16 December 2002 17:11
To:
This email address is being protected from spambots. You need JavaScript enabled to view it.
Subject: What about 'assigned()' function instead of 'null' value?
Hi All,
Usage of 'special value null' (if used consequently) gives programmer a little bit of assurance that a given variable is initialized and although have no valid value/reference but its content can be determined by comparison like e.g.
if variable <> null then {
: // do something without memory access violation error
}
This idea of initializing variables in TTCN-3 was employed for initialization of variables of the address type, handling component references and default references.
Usually, read access to any declared but not initialized variable, not necessarily only of address, component and default type, leads to 'Memory Access Violation' error. 'Null' solution is not flexible, it rather looks like a temporary fix for some cases. As a temporary fix it should be removed and replaced by a more suitable all-purpose solution.
'Memory Access Violation' error is a common programmer error caused by wrong/missing initialization code for variables/objects. Although it can be avoided but depending on the code complexity probability of occurrence is various. The most important is to give programmer a kind of diagnostic tool to check which accessed variable/objects is not initialized.
Function assigned() returns Boolean value true, if passed as an argument a variable or object reference is valid, i.e. the variable is assigned a value or points to a valid object.
Example of usage:
if assigned(variable) then {
:
}
Proposal to standard:
C.32 Assigned function
assigned (anytype reference) return boolean
This function returns boolean value true if for a given reference, which was passed as an argument, the memory was not only allocated but also assigned, i.e. the referenced value was not only declared, but it was also initialized and the value of the referenced object is valid.
Function returns boolean value false for a reference, which was not initialized.
EXAMPLE:
var MyCompType1 MyInst1;
if assigned(MyInst1) then {
:
}
else {
:
}
The purpose of the function is to protect runtime-code execution. In case of e.g. an access to not initialized variable of integer type or variable handling default reference an error exception 'Memory Access Violation' should be generated by the test system.
Best Regards,
Mariusz Kupiec
Korea przeciw najnowszemu Bondowi >>>
link.interia.pl/f16ac