Function pass va_list to another function

Find and share HowTos to various installations / configurations!
Search

Post Reply
4 posts • Page 1 of 1
User avatar
CyaNn
Posts: 97
Joined: Tue Nov 23, 2010 8:48 am

Function pass va_list to another function

Post by CyaNn » Sun Oct 18, 2020 4:03 am

Hello all !

A question is really desapointing me in CTRL / CTRL++ from a while.
Here it is ! I want to pass arbitrary number of parameter from a function to another (like javascript REST parameters / SPREAD operator).

Here is my exampe :

Code: Select all

class MyClass {

  public caller() {
    callIt("test1", "test2");
  }

  private callIt(... /* pass this */) {
    callFunction(this.called, ... /* to this */);
  }

  private called(string param1, string param2) {
    DebugTN("WORKS !!!!", param1, param2);
  }
}
A really apreciate if someone have a solution to do that. :-)
Regards.
Yann

User avatar
CyaNn
Posts: 97
Joined: Tue Nov 23, 2010 8:48 am

Re: Function pass va_list to another function

Post by CyaNn » Sun Oct 18, 2020 4:11 am

Here is the javascript example

Code: Select all

function caller() {
	callIt("param 1", "param 2");
}

function callIt(... params) {
	called(... params);
}

function called(... params) {
	console.log("Works !", params[0], params[1]);
}

caller();
See working it here : https://jsfiddle.net/CyaNn/rzayd4uo/3/

gschijndel
Posts: 176
Joined: Tue Jan 15, 2019 2:12 pm

Re: Function pass va_list to another function

Post by gschijndel » Mon Oct 19, 2020 1:39 pm

I see no reason why it should not work. Did you try to pass the va_list to another function?

Code: Select all

  private callIt(... /* pass this */)
  {
    va_list args;
    
    va_start(args);
    
    callFunction(this.called, args);
    
    va_end(args);
  }

  private called(...)
  {
    va_list args;
    
    int argc = va_start(args);
    
    Debug(getCurrentTime(), "WORKS !!!!");
    for (int i = 1; i < argc; i++)
    {
      Debug(args[i]);
    }
    DebugN(args[argc]);
    
    va_end(args);
  }

User avatar
CyaNn
Posts: 97
Joined: Tue Nov 23, 2010 8:48 am

Re: Function pass va_list to another function

Post by CyaNn » Tue Oct 20, 2020 2:48 pm

Many thanks for the response.

I think the problem comme from the function "callfunction" of wincc api :

This does not works :

Code: Select all

class MyClass {

  public caller() {
    callIt("test1", "test2");
  }

  private callIt(...) {
    va_list args;
    va_start(args);
    
    callFunction(this.called, args);
    
    va_end(args);
  }

  private called(string param1, string param2) {
    DebugTN("WORKS !!!!", param1, param2);
  }
};

Post Reply
4 posts • Page 1 of 1