773 views
in Embedded Wizard Studio by

Hello,

is it possible in EW to pass a pointer to a function and modify the value, as you would do it in C/Cpp?

bool GetValue(int ID, int* value)
{
	if(...)
	{
		*value = 123;
		return true;
	}
	else
	{
		return false;
	}
}
res = GetValue(ID, &value);

Best regards

Jonas

1 Answer

0 votes
by
 
Best answer

Hello Jonas,

not directly. What you can do:

Option 1: You can pass an object containing a variable. Within the method you can access and modify the variable. For this application case you implement a new class containing one or more variables. Then you create an instance of the class and pass it in the method invocation. To improve performance you can reuse one and the same object avoiding so its recreation.

Option 2: Another possibility involves property references. In this case the value of interest is stored within a property. When invoking the method you pass a reference to the property. Within the method you can derefence the passed reference and so access and modify the property.

Both approaches are very similar to how pointers work in C. However, the support limits to objects and properties. Pointers pointing directly to variables or arrays are not supported.

I hope it helps you further.

Best regards

Paul Banach

Ask Embedded Wizard - Archive

Welcome to the Ask Embedded Wizard archive. This community forum served us well for many years, but we've evolved our support approach!

Your resources:

The Embedded Wizard Online Documentation provides comprehensive documentation, tutorials, examples and ready-to-use software packages.

For dedicated assistance, explore our Embedded Wizard Product Support.

You can still browse the valuable discussions from our community history here.

Embedded Wizard Website | Privacy Policy | Imprint

...