Hello, for a program i'm translating from 68k to PPC i have a problem on a varargs function. Or better.. i have a lot of problems..
First of all: The original definition
struct aReq *CreateDummy(ULONG flags, Tag tag1, ...);
i've changed it to use VARARGS68K parameters. so now i have:
struct aReq * VARARGS68K CreateDummy(ULONG flags, Tag tag1, ...);
When i enter into the function as usual i try to pack them as TagItem using the va_start/va_end macro
va_list ap; struct TagItem *tags; va_startlinear(ap, tag1); tags = va_getlinearva(ap, struct TagItem *);
The function in the old 68k program is called in this way:
pr = CreateDummy(MYULONGFLAG, A_Title, MyTitle, A_Objects, MyObjects, A_Addresses, MyAddr, TAG_END);
Now. let's start with the various problems..
If i print them with a cycle:
if (tags) { Tag tag; while ((tag=tags->ti_Tag)) { printf("tags->ti_Tag=%lx - %d\n",tags->ti_Tag,tags->ti_Tag); tags++; } } va_end(ap);
my ti_tag values are wrong.. they not are the correct defined in the .h file
And this is the first problem.
My huge doubt is that one.. This function calls another function defined into a .library file that i've translated for ppc use and it calls the function in this way:
in the 68k version it use the tags passed into the stack using the pointer to the first tag:
pr = CreateLibDummy(A_Tag1, Taga1, A_Tag2, Taga2, A_Tag3, Taga3, A_Tag4, Taga4, TAG_MORE, &tag1); // no TAG_END required
for the ppc use i've changed them into:
pr = CreateLibDummy(A_Tag1, Taga1, A_Tag2, Taga2, A_Tag3, Taga3, A_Tag4, Taga4, TAG_MORE, tags); // note the tags variable
So i think there is another problem. When the external library is called it packs the Tag parameters into TagItem like the previous one, indeed if i use the same cycle to print the ti_Tag, the first 4 values are correct, the TAG_MORE is printed as 2 (and it is correct) but the other parameters are always wrong.
So my question are:
1) Is the pack needed in the first function since i cannot pass the tags like the 68k version?
2) If i pack them can i avoid to repack them when my library receive the parameters?
3) is there a solution??
Hope i'm clear..
Thank you
The problem is that you list the first vararg parameter as a variable (tag1) which is wrong. Instead your function prototype should like this:
and the va_start code should be like:
i think i've alredy tried it.. but i'll retry when i go home. But what about the tags passend into TAG_MORE? it is correct to pack them? And what about the library that receive them as TagItem instead of Tag?
No idea what you mean by packing here but this code on ppc-amigaos:
is equivalent to the following code on m68k-amigaos:
or without using tag1 (m68k-amigaos only as above):
Ok, but did you have an external PPC library that receive this parameters?
The problem is that i have something like this:
MyProgram calls function A inside the program
The function A will use va_start/va_end macro
The function A call an external .library that receive this parameters in this way:
CalledFunction(Tag1, 1, Tag2, 2, TAG_MORE, myvatags)
The ppc library will use va_start/va_end on received parameters. So, for the first two couple of parameters it is working, so i will have {Tag1, 1} and {Tag2, 2}. I halso receive TAG_MORE correct but the next parameter is the TagItem i have passed from my function A.
How the va_startlinear change them?
This part of your code does not work with TAG_MORE. You have to use NextTagItem() to traverse a tag list correctly.
well that part was working because there no was tag more in the first function.. but basically it was the problem since the tag pointer was increased.. and then passed wrong to the second function.. now all is working perfectly..