Can i get the name of the argument that was passed in a function with the # macro definition ?

 

Code explains it :

#define NAMEOF(x) #x

template<typename X>
string findName(X &value){
return(NAMEOF(value));
}
int OnInit()
  {
//---
  int macaroni=0;
  string name=findName(macaroni);
  Print(name);
//---
   return(INIT_SUCCEEDED);
  }

i expected that i'd get "value" can i get "macaroni" ? 

tx

EDIT : 

what i'm trying to do is setup a wrapper around a variable or array and auto-assign the name the user has given it .

This is the best workaround i came up with ,but the user will be annoyed typing that in (the passvalueandname (the user has access to the source code))

Goal : 

void setup_with_name(int value,string _name=""){
     Print("Setup "+_name+"="+IntegerToString(value));
     }

Temporary macro : 

#define PASSVALUEANDNAME(x) x,#x

setup_with_name(PASSVALUEANDNAME(macaroni));
Also is there a macro that gets the typename ? 
 
Lorentzos Roussos:

Code explains it :

i expected that i'd get "value" can i get "macaroni" ? 

tx

EDIT : 

what i'm trying to do is setup a wrapper around a variable or array and auto-assign the name the user has given it .

This is the best workaround i came up with ,but the user will be annoyed typing that in (the passvalueandname (the user has access to the source code))

Goal : 

Temporary macro : 

Why are you using a function and not directly the macro ?

#define findName(x) #x

//template<typename X>
//string findName(X &value) {
//   return(NAMEOF(value));
//}
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart() {
//---
   int macaroni=0;
   string name=findName(macaroni);
   Print(name);

}

Probably I don't understand what you are trying to achieve. Please provide code closer to your goal in this case.

 
Alain Verleyen #:

Why are you using a function and not directly the macro ?

Probably I don't understand what you are trying to achieve. Please provide code closer to your goal in this case.

I've explained in the edit 

Can i get the name of the variable / array that was passed to the function ?

And is there a macro for getting the typename ?
 
Lorentzos Roussos #:

I've explained in the edit

Ok.