Welcome, Guest. Please login or register.

Author Topic: varargs compatibility probs with PPC Oses./Passing to 2nd function  (Read 3935 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Thomas

Re: Passing a function's variable arguments to a 2nd one...?
« on: September 11, 2005, 11:27:20 AM »

You could do it like AmigaOS does it:

Code: [Select]

void SomeFunctionA (int a,int *b)
{
/* whatever it does, do it here */
}

VARARGS68K void SomeFunction (int a,...)
{
va_list ap;
va_startlinear (ap,a);
return (SomeFunctionA (a,va_getlinearva (ap,int *)));
}

void SecondFuncA (int a,int *b)
{
/* do some stuff */
SomeFunction (a,b);
/* do some stuff */
}

VARARGS68K void SecondFunc (int a,...)
{
va_list ap;
va_startlinear (ap,a);
return (SecondFunc (a,va_getlinearva (ap,int *)));
}


Bye,
Thomas

Offline Thomas

Re: Passing a function's variable arguments to a 2nd one...?
« Reply #1 on: September 11, 2005, 04:15:16 PM »

What I wanted to say is, you should *avoid* varargs. Do not use varargs. Write your function *without* varargs. Make your functions accept a pointer to an array which contains the arguments.

Then, in order to call the function with varargs, create a stub which fetches a pointer to the varargs array and sends it to the actual function.

That's how it always was in AmigaOS. AmigaOS functions never accepted varargs. The actual function always only accepted an array of tag items. But there is a small varargs stub which calles the original function passing a pointer to the varargs array.

Getting this pointer is very easy on 68k but difficult on PPC because the PPC does not allocate all arguments on the stack.
 
You should read the docs before you start to program. There is a chapter about varargs in one of the PDF files.

AFAIK using varargs outside the originating function is not supported.

Bye,
Thomas

Offline Thomas

Re: Passing a function's variable arguments to a 2nd one...?
« Reply #2 on: September 15, 2005, 06:37:01 PM »
Quote

&dest + 1


This does not work on PPC code. I told you there is a chapter about varargs in the OS4 docs. Why don't you read it ? I even gave you an example how it is done in OS4. Why don't you look at it ?

Bye,
Thomas

Offline Thomas

Re: Passing a function's variable arguments to a 2nd one...?
« Reply #3 on: September 19, 2005, 06:22:59 PM »

VBCC uses __reg("d0").

Bye,
Thomas