Connecting Tech Pros Worldwide Forums | Help | Site Map

variable arg macro

Newbie
 
Join Date: Nov 2006
Posts: 16
#1: Oct 24 '07
I am using something like below which is working fine on solaris (sun studio 10).

------------------------------
#define START_LOG( p_aLevel, p_aFormat, ... ) \
if (p_aLevel > cm_aLogger_ptr->getLogSeverity()) \
CUnicornLogger::putLog( p_aLevel, p_aFormat, __VA_ARGS__)

START_LOG( p_aLevel, p_aFormat, a, b, c);
------------------------------

but the same is raising compiler error on VC++6. As the compiler cannot understand the ellipsis and __VA_ARGS__. It seems that variable argument macro is not supported on NT.

I have included stdarg.h.

Can anybody tell whether this is supported on NT or not. If not, what else I can do?
Thanks in advance.

Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,183
#2: Oct 24 '07

re: variable arg macro


Quote:

Originally Posted by saby

Can anybody tell whether this is supported on NT or not. If not, what else I can do?

It is not NT is it is the version of C/C++ that is being used. Variable argument macros are quite a late addition to the standard and VC++ 6.0 is now 8 years old.

This will only be supported by the latest compilers.
Newbie
 
Join Date: Nov 2006
Posts: 16
#3: Oct 24 '07

re: variable arg macro


Quote:

Originally Posted by Banfa

It is not NT is it is the version of C/C++ that is being used. Variable argument macros are quite a late addition to the standard and VC++ 6.0 is now 8 years old.

This will only be supported by the latest compilers.

Hi Banfa,
Thank you for your reply.

Since I am working with VC++6, I have planned something like below,

void START_LOG(level, ... )
{
here I want to have the variable argument in some structure, say va_list, and pass that as it is in another function say,

log(level, <variable arguments>);

probably that requires copying from the local stack to the function stack using macro.
I can not use va_arg, because I dont know the types of arguments.
}

can you please help me. Or is there any other means to achieve this.
regards,
Saby
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,183
#4: Oct 24 '07

re: variable arg macro


To use a variable argument list in a function you have to know what arguments have been passed.

printf, for instance, gets round this by having the arguments describe in the format string which it parses.

You can not tell from the data alone in a va_list what the types of the arguments are.
Newbie
 
Join Date: Oct 2007
Posts: 1
#5: Oct 31 '07

re: variable arg macro


Saby,

It is possible to use variable arguments functions using MSVC and has been since MSVC 1.0. However, MSVC does not implement variable arguments using the standard macros.

To use Variable arguments you need to use the you need to use the MS specific macros. Using your example would be done as:

Expand|Select|Wrap|Line Numbers
  1. void START_LOG(level, ...)
  2. {
  3.  
  4.     va_list arglist;
  5.     va_start(arglist, pszFormat);
  6.                 log(level, arglist);
  7.     va_end(arglist);
  8. }
see http://msdn2.microsoft.com/en-us/lib...d8(VS.80).aspx for more info.
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,183
#6: Oct 31 '07

re: variable arg macro


Quote:

Originally Posted by djstrangeways

Saby,

It is possible to use variable arguments functions using MSVC and has been since MSVC 1.0. However, MSVC does not implement variable arguments using the standard macros.

To use Variable arguments you need to use the you need to use the MS specific macros. Using your example would be done as:

Expand|Select|Wrap|Line Numbers
  1. void START_LOG(level, ...)
  2. {
  3.  
  4.     va_list arglist;
  5.     va_start(arglist, pszFormat);
  6.                 log(level, arglist);
  7.     va_end(arglist);
  8. }
see http://msdn2.microsoft.com/en-us/lib...d8(VS.80).aspx for more info.

Those are the standard macros
Reply