conditional operator again



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 .....

.



Relevant Pages

  • Re: ATL/COM memory management
    ... typedef char array; ... delete ptr; ... to Microsoft's news server, it doesn't report any problems with ... the posting, yet the posting never appears on the server? ...
    (microsoft.public.vc.language)
  • Re: explanation needed on const pointers
    ... const char *ptr; ... char *const* ptr; ... What is the best way to reference a previous posting? ... looks horrible and I can't from the style is the URI in long-lived or ...
    (comp.lang.c)