Page 1 of 1

passing address pointers thru functions

Posted: June 19th, 2013, 12:03 am
by pierrew
Hello Greg,
We are working on automatic xml scripting to convert tables using table functions (such as tblrow and tblsum, etc.) to xml. We want to create a function that can do the work without copy and pasting huge amount of code. So the question is there a way to pass an item address (pointers)? For example

Code: Select all

function writeTable (&tableName, &itemName)
     // some code to write the table to an xml file
end;

...
PROC HOUSE_TENURE
postproc
     writeTable(&TABLE1, &$);
Thanks,
Pierre

Re: passing address pointers thru functions

Posted: July 1st, 2013, 6:38 pm
by Gregory Martin
The concept of pointers doesn't exist in CSPro. When you pass numeric and alphanumeric values as function parameters, they are passed by value, meaning that any changes made within the function don't affect the passed in values. For example:
function myFunc(value)

    value =
10;

end;

numeric xxx;

// ....

xxx =
5;

errmsg("xxx = %d",xxx); // prints 5

myFunc(xxx);

errmsg("xxx = %d",xxx); // still prints 5
However, when you pass arrays to functions, they are passed by reference (like a pointer), so any changes made in the function will affect the passed-in array. In your example you will be able to modify tableName from within writeTable but you won't be able to modify itemName.