Link to home
Start Free TrialLog in
Avatar of ofirg
ofirg

asked on

how can i pass #define to function as an argument

suppose i have
#define DEF1 {1,1}
#define DEF2 {2,2}

int func(x)
{  
  int *i = x ;
  return 0;
}

what should be x?
Avatar of DanRollins
DanRollins
Flag of United States of America image

It is hard to tell from the question, but I think you want to know how you can pass a two element array to a function.

You need to allocate it:

   int anTwoElemArray[2]= DEF1; // {1,1}

   int nRet= func( anTwoElemArray );
or
   int nRet= func( &anTwoElemArray[0] );
or
   int* pan= anTwoElemArray; // point to first element
   int nRet= func( pan );

But the question is quite ambiguous and, candidly silly.  So why not describe what you really want to do?  

-- Dan
Avatar of ofirg
ofirg

ASKER

i want to pass the #define itself to function as an argument not by assign it to other variable first
somthing like

i = func( (int*) DEF1);
The constans DEF1 and DEF2 are recognized all over the program , including inside the function.
Why do you want to pass it ?
ASKER CERTIFIED SOLUTION
Avatar of IainHere
IainHere

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
But the question is quite ambiguous and, candidly silly.  So why not describe what you really want to do?  

-- Dan
Avatar of ofirg

ASKER

thanx man.

const int DEF1[] = {1,1}; works and help me very much.