Testing a String Pointer as a Pointer

Component Testing for C

Use the string_ptr keyword on a VAR line to work around the ambiguity of the C language between arrays and pointers.

For example the following VAR line (supposing the declaration char* string;) will generate C code that will copy the string into the memory location pointed by string.

VAR string,   init = "foo", ev = init

-- This is the "traditional" way

 

Of course, if no memory was allocated to the variable, this is not possible.

The following alternative approach causes the string to point to the memory location containing "foo". The string is then compared to "foo" using a string comparison function:

VAR string, string_ptr, init = "foo", ev = init

-- Note the additional field in the line

 

This syntax allows you to initialize the variable to "NIL", and to compare its contents to a given string after the test.