-3

I have a question. Say I have this code:

int myfunc(int arg-a, int arg-b); 
int mywrapperfunc(obj a, obj b);

mywrapperfunc is supposed to wrap myfunc. mywrapperfunc discards the first argument and takes the second, which is an array. I then uses the array items as parameters. But say I don't know how many parameters myfunc takes, nor do I know how many items are in the array-type object(b). How would I programmatically call myfunc with the correct number of args? The number of args handed over would be the same as the number of items in the array-type object. EDIT: arg-a and arg-b are supposed to come from the array-type object. I split the object into the args. EDIT: I'm trying to wrap Cython with some sense involved, hiding most background jobs.

roalz
  • 2,699
  • 3
  • 25
  • 42
kirbyfan64sos
  • 10,377
  • 6
  • 54
  • 75
  • 6
    I didn't understand any of this. – Kiril Kirov Apr 04 '13 at 13:38
  • 1
    Can you give an example of what you'd like to do? To start, `arg-a` and `arg-b` are not valid identifiers. – Joseph Mansfield Apr 04 '13 at 13:39
  • 1
    Why not use an `std::vector` or `std::array` (if available)? Both of them know their size – dario_ramos Apr 04 '13 at 13:40
  • 1
    What is the purpose of discarding the first argument? Why is it a parameter then? – JBentley Apr 04 '13 at 13:41
  • Sounds like you are trying to build your own language. Typically, then, you have to pass arguments as "argc, argv[]". – Mats Petersson Apr 04 '13 at 13:41
  • @JBently: It's a long story. For starts, another app calls a library which calls the semingly useless first arg. – kirbyfan64sos Apr 04 '13 at 13:54
  • 1
    For `mywrapperfunc` to call `myfunc`, it must either know about `myfunc` statically or have a pointer to it. Either way, it statically knows the type and therefore the number of argument. If that _isn't_ what is happening, please show how this is set up & invoked. – Useless Apr 04 '13 at 14:01

1 Answers1

1

It's called reflection, you cannot do this with c++. Use another languages like java or c# for that.

SpongeBobFan
  • 964
  • 5
  • 13
  • Is there some Java wrapper I can use then? This is a wrapper that, do to some special reasons, must be written in C++. Is there some way I could do that part in another language and link it with the C++ object file? – kirbyfan64sos Apr 04 '13 at 13:50
  • @kirbyfan64sos How about addressing the points raised as comments on the question (in particular, giving a clear code example), then hopefully someone can help you further. – JBentley Apr 04 '13 at 13:52
  • @SpongeBobFan: How about boost::reflection? – kirbyfan64sos Apr 04 '13 at 13:52
  • @kirbyfan64sos, first you should clearly explain why do you need that. Maybe you can avoid it? It is great idea to avoid reflection everytime it is possible. – SpongeBobFan Apr 04 '13 at 13:57
  • @kirbyfan64sos, I don't know about `boost::reflection`, but you should watch a picture in [that topic](http://stackoverflow.com/questions/87932/attribute-reflection-libraries-for-c) to understand what are you trying to do. – SpongeBobFan Apr 04 '13 at 14:00
  • @SpongeBobFan: I am trying to make a wrapper for Cython. The person hands a copy of the function, the wrapper splits self and args as needed and gives the function the correct args. It will raise an error if Python gives too much/little args or improper data type. The goal is to make Cython's workings less obvious to the user. – kirbyfan64sos Apr 04 '13 at 14:01