#define's with variable length argument lists? 
Author Message
 #define's with variable length argument lists?

I'd like to add some debugging output to programs that use a library
I've written, using this hack:

:  
:  #defing glorp(a,b,c)  _glorp(__FILE__, __LINE__, a, b, c)
:  
:      <...>
:  
:      glorp(3.1415926, 0x666, "glorp has intelligent error messages!");
:  

This allows glorp to report from where it was called.

That's great, but what if glorp can have a variable-length argument list?
I don't think that #define can handle this...  Can it?  i.e. can I indicate
somehow that the last argument is optional?

I know that I could do the following:

:
:  #define glorp(a)     {  _set_error(__FILE__, __LINE__);      \
:                          _glorp a  }
:
:      <...>
:
:  glorp((27, "This is ugly!"));
:

but this is inefficient, ugly, and breaks all of my existing applications.

Is there some good way around this?  A way that would be invisible to
existing applications (with just an appropriate #define or two in the
right .h file)?

Thanks in advance,






Tue, 18 May 1993 10:32:36 GMT  
 #define's with variable length argument lists?

Quote:

>:  #define glorp(a,b,c)  _glorp(__FILE__, __LINE__, a, b, c)
>:      glorp(3.1415926, 0x666, "glorp has intelligent error messages!");

>That's great, but what if glorp can have a variable-length argument list?
>I know that I could do the following:
>:  #define glorp(a)     {  _set_error(__FILE__, __LINE__);      \
>:                      _glorp a  }
>:  glorp((27, "This is ugly!"));
>but this is inefficient, ugly, and breaks all of my existing applications.

Just off the top of my head...  This may work for you.

: #define glorp _set_error(__FILE__,__LINE__), _glorp

The macro definition specifies _no_ parameters.  Specifically,
whatever parenthesised expression you code following a call to glorp is
not considered part of the macro expansion, but will simply appear as
the parameters to the enclosed trailing call to _glorp.

--
First comes the logo: C H E C K P O I N T  T E C H N O L O G I E S      / /  
                                                                    \\ / /    
Then, the disclaimer:  All expressed opinions are, indeed, opinions. \  / o
Now for the witty part:    I'm pink, therefore, I'm spam!             \/



Tue, 18 May 1993 13:58:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. functions with variable length argument lists

2. Passing Variable-Length Argument Lists

3. Variable-length Argument List

4. Variable length argument lists and NULL

5. Passing variable length argument list to functions

6. Variable length argument list handling

7. Variable Length Argument list

8. variable-length argument lists

9. Variable length argument list example

10. Variable Length Argument Lists?

11. Help: Variable-length Argument Lists

12. variable length argument list

 

 
Powered by phpBB® Forum Software