Computing.Net > Forums > Programming > Passing structs va_list

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Passing structs va_list

Reply to Message Icon

Name: AndyAmstrad
Date: December 8, 2002 at 08:29:14 Pacific
OS: Windows2000
CPU/Ram: Pentium 3
Comment:

Hi there

Im in the process of implementing an XMLRPC library(nothing fancy) for a Uni project, written in C.

I have a problem and that I have a function called XmlRpcBuildRequest
which basically builds an xmlrpc request as an xml documnent.

It will be something like :

XmlRpcBuildRequest("My.Method","MyParam1",100,100.0,myStruct);

It will bascially take a variable arg list and use this list to build the xml.

All this works fine apart from the struct parameter.

How do I pass any struct defined by the user and then get the contents from the struct to build the xml params e.g.

struct foo
{
int x;
int y;
};


struct foo a;

a.x=10;
a.y=20;

I then some how need to re-package the struct from the xmlrpc request on the server side to pass the struct into the server method.

Any good ideas?

I hope im clear in my explanation.

Many thanks in advanced.



Sponsored Link
Ads by Google

Response Number 1
Name: Jeff Graver
Date: December 10, 2002 at 13:06:12 Pacific
Reply:

The only way I know of to pass "any struct" to a function is by way of a (void*).

This doesn't give you any clue as to what (or even how much) is inside the struct. You'll need to know at least the "how much" part so you'll probably need to pass a length as well as a pointer.

But you still don't know what's in the struct. And that's the end of the C tricks. In order to go any further, you have to give up on "any struct" and demand that the user structure the data in SOME fashion. You could, for example, pass data as ASCII text that can be subjected to a parser on the remote side. Or you could limit the structs that are used to some set that defines the sort of thing that the server knows how to deal with.

XmlRpcBuildRequest can be constructed without specific knowledge of the contents of the structs, but I don't think the server side software can. This may be enough to solve your dilemma, since it could be that MyMethod is to be passed the struct for interpretation and MyMethod knows, by definition, how to pass the struct that comes with it. In this case, simply have MyMethod accept the struct as a (void*) and cast it to the struct type of interest - then check carefully for struct validity (no sense in opening yourself to hackers).

Make any sense?

Jeff


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Passing structs va_list

Passing pointers between functions www.computing.net/answers/programming/passing-pointers-between-functions/9083.html

Accessing members of a struct www.computing.net/answers/programming/accessing-members-of-a-struct/10070.html

Problem with strings in structs www.computing.net/answers/programming/problem-with-strings-in-structs/6284.html