This topic describes the major differences between the
4Test programming language and C. C programmers should read this section for a quick overview of
4Test.
Data Types
C data types for DLL callouts
In addition to the
4Test data types,
Silk Test Classic supports certain C data types for use in calling out to functions in DLLs.
4Test and C Keywords Compared
4Test supports most of the data types available in C;
4Test also has a type ANYTYPE that can hold any base type. The keywords that
4Test uses for its base types are slightly different, as illustrated in the following table.
Data Type/Difference
|
C Declaration
|
4Test Declaration
|
Any type: Stores data of any type.
|
|
anytype a
|
Array: Arrays in
4Test can be dynamically resized.
|
int ai[10];
|
array [10] of integer ai
or
integer ai[10]
|
Boolean: Stores either TRUE or FALSE.
|
int b;
|
boolean b
or
int b
|
Character:
4Test has no data type for single characters.
|
char c;
|
string c
|
Enumerated: To declare a
4Test variable of type COLOR:
|
enum COLOR
{red, white, blue};
|
type COLOR is enum
red
white
blue
|
Floating-point: Real numbers in
4Test are double-precision
|
float f;
double d;
|
real f
real d
|
Integer:
4Test integers are long (4 bytes) and signed
|
int i; long, short, unsigned
|
integer i
|
List:
4Test has dynamic lists
|
|
list of integer li
|
Numeric:
4Test NUMBER type stores either integers or floating point numbers.
|
|
number n
|
Pointer:
4Test does not have pointers; however, data can be indirectly referenced using the @ operator, as described below.
|
char *p;
|
|
Pointer to function:
4Test does not have pointers; however, data can be indirectly referenced using the @ operator, as described below.
|
int (*func) ();
|
|
String:
4Test strings are dynamically allocated; you do not need to declare their lengths.
|
char s[5];
|
string s
|
Structure:
4Test user-defined types take the place of structure types.
|
struct Person
{
char name[8]
int age;
}
|
type Person is record
string name
integer age
|
Union:
4Test does not have unions. Use a variable of any type.
|
|
|
User-defined type
|
typedef struct Person
PERSON_INFO;
|
type PERSON_INFO is Person
|
Operators
Type Cast Operator Differences
4Test and C use different formats for type casting:
4Test format
|
[typename] expression
|
C format
|
(typename)
expression
|
Reference (@) Operator Differences
4Test does not have pointers. Use the reference @ operator to reference variables and functions, as shown in this example:
TestFunc ()
Print ("In TestFunc")
main ()
STRING s = "foo"
STRING sVariable = "s"
STRING sFunc = "TestFunc"
Print (s) // Prints: foo
Print (sVariable) // Prints: s
Print (@sVariable) // Prints: foo
//Calls TestFunc, prints: In TestFunc
@(sFunc) ()
Equality (==) operator differences
The following code compiles in C, but not in
4Test:
if ((i=5) == TRUE)
This difference is intentional. Because this construct can lead to unreadable code,
4Test does not allow it.
Flow of Control
Looping and Iteration Differences
In addition to a C-style for loop,
4Test also has a for loop of this form:
for i = 1 to n step 5
4Test has a for each statement , for iterating over a list:
for each PartNum in PartNumList
4Test does not have a do while loop.
Conditional Differences
The
4Test switch statement can be used on any expression; the case statement that goes with
switch can contain a list of values, as well as a single value. In
4Test, control automatically breaks out of a
switch when the end of the case is reached (as opposed to C, where you must explicitly break out of the
switch at the end of each case).
The
4Test select statement provides an alternative to a series of if statements; the case statement that goes with
select contains a boolean expression that, if true, causes
4Test to execute the statements in the case. As with switch/case,
4Test automatically breaks out of the select at the end of the case.
4Test Controls Not in C
4Test has the following flow of control statements that do not correspond to C statements:
- exit
- Halts execution of a script.
- raise and reraise
- Raise and re-raise exceptions, respectively.
- parallel, spawn, and rendezvous
- Support concurrent programming.
Argument Passing Modes
Passing by Value
To pass by value, make a function parameter an in (input) parameter (the default). Use an in parameter when you only want to use only the parameter’s value within the function.
Passing by Reference
To pass by reference, make a function parameter an inout or out parameter.
- Use an
out parameter if you only want to set the parameter’s value.
- Use an
inout parameter if you want to get the parameter’s value and you want the function to change the value and pass the new value out.
Preprocessor Directives
4Test does not have a preprocessor. To include a file, use the use statement.