J
junky_fellow
Hi guys,
I posted a query yesterday and got some good responses. However,
before posting
I did some simplications in my code. Now, I am posting what I exactly
want and what
I have done. I want your views if I have done it correctly or not ?
Are there any loopholes ?
Or can it be done in a better way ?
My objective is to convert a function func() to macro for efficiency.
The function func() is:
char ** func( int var, char **ptr)
{
if(var == 1)
return(ptr);
if(var == 2) {
if(*ptr == NULL)
return NULL;
else
return ptr;
}
func2(var, ptr);
}
I am using this function as follows:
int main(void)
{
char **ptr, **res;
int flag;
/* some code */
res = func(flag,ptr);
}
I have written the following macro.
#define func(flag, ptr) \
((flag == 1 || flag == 2) \
? (flag == 1) \
? (char **)ptr \
: ( flag == 2 && (*ptr == NULL) )
? NULL \
: (char **)ptr \
: (char**)func2(flag, ptr))
I want to know, if this would work fine or not ? Is there a better way
of doing this ?
thanks a lot in advance for any help .....
I posted a query yesterday and got some good responses. However,
before posting
I did some simplications in my code. Now, I am posting what I exactly
want and what
I have done. I want your views if I have done it correctly or not ?
Are there any loopholes ?
Or can it be done in a better way ?
My objective is to convert a function func() to macro for efficiency.
The function func() is:
char ** func( int var, char **ptr)
{
if(var == 1)
return(ptr);
if(var == 2) {
if(*ptr == NULL)
return NULL;
else
return ptr;
}
func2(var, ptr);
}
I am using this function as follows:
int main(void)
{
char **ptr, **res;
int flag;
/* some code */
res = func(flag,ptr);
}
I have written the following macro.
#define func(flag, ptr) \
((flag == 1 || flag == 2) \
? (flag == 1) \
? (char **)ptr \
: ( flag == 2 && (*ptr == NULL) )
? NULL \
: (char **)ptr \
: (char**)func2(flag, ptr))
I want to know, if this would work fine or not ? Is there a better way
of doing this ?
thanks a lot in advance for any help .....