passing address pointers thru functions

Discussions about editing and cleaning data
Post Reply
pierrew
Posts: 47
Joined: August 8th, 2012, 5:20 am
Location: Pohnpei, Federated States of Micronesia

passing address pointers thru functions

Post 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
Gregory Martin
Posts: 1793
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: passing address pointers thru functions

Post 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.
Post Reply