va_start issue in GCC 3.3.1

R

Ryan Liu

All,

Now I meet a problem, when I use va_start in GCC 3.3.1.
The following is the problem description:
Source Code:

void
Message (severity, message, va_alist)
int severity;
MSG *message;
va_dcl
{
va_list args;

va_start(args);

/* Print the error message in standard format */

(void) vprmsg ( severity, message -> msg_format, args);

va_end(args);

return;

} /* end function Message
Error message:

+
/opt/exp/gnu/bin/gcc -O -I../../../tl/hdr -I../../../tl/pagfilegen/hdr -I- -
o pagutil.o -c pagutil.c
pagutil.c: In function `Message':
pagutil.c:937: error: parse error before "va_dcl"
pagutil.c:941:22: macro "va_start" requires 2 arguments, but only 1 given
pagutil.c:941: error: `va_start' undeclared (first use in this function)
pagutil.c:941: error: (Each undeclared identifier is reported only once
pagutil.c:941: error: for each function it appears in.)
pagutil.c:954:8: macro names must be identifiers
make: *** exit code 1 making pagutil.o

I don't know how to do it. Would you mind giving some suggestion?

Thank you very much in advance.

Ryan
 
R

Rolf Magnus

Ryan said:
All,

Now I meet a problem, when I use va_start in GCC 3.3.1.
The following is the problem description:
Source Code:

void
Message (severity, message, va_alist)
int severity;
MSG *message;
va_dcl

Why are you using this enormously old K&R style for function
definitions? Is that even valid in C++?
{
va_list args;

va_start(args);

/* Print the error message in standard format */

(void) vprmsg ( severity, message -> msg_format, args);

va_end(args);

return;

} /* end function Message
Error message:

+
/opt/exp/gnu/bin/gcc -O -I../../../tl/hdr -I../../../tl/pagfilegen/hdr
-I- - o pagutil.o -c pagutil.c
pagutil.c: In function `Message':
pagutil.c:937: error: parse error before "va_dcl"

I never heared of "va_dcl". Did you need that in K&R style?
pagutil.c:941:22: macro "va_start" requires 2 arguments, but only 1

That's right. The first argument ist the va_list, the second one is the
last non-variable parameter of your function.
given pagutil.c:941: error: `va_start' undeclared (first use in this
function) pagutil.c:941: error: (Each undeclared identifier is
reported only once pagutil.c:941: error: for each function it appears
in.)

You probably forgot to #include said:
pagutil.c:954:8: macro names must be identifiers

No idea about that.
make: *** exit code 1 making pagutil.o

I don't know how to do it. Would you mind giving some suggestion?

#include <cstdarg>

void Message(int severity, MSG* message, ...)
{
va_list args;

va_start(args, message);
vprmsg(severity, message->msg_format, args);
va_end(args);
}
 
D

David Rubin

Ryan said:
All,

Now I meet a problem, when I use va_start in GCC 3.3.1.
The following is the problem description:
Source Code:

void
Message (severity, message, va_alist)
int severity;
MSG *message;
va_dcl

Why are you using non-ansi syntax with gcc 3.3.1?
{
va_list args;

va_start(args);
[snip]
(void) vprmsg ( severity, message -> msg_format, args);

va_end(args);

IIUC, you should declare va_alist as va_alist and then call vprmsg() with
va_alist. You don't need args at all since va_alist is already a va_list object.
return;

} /* end function Message

/david
 
R

Ryan Liu

Hi All,

Thank you very much for your help.
I have fixed it.
The method is following for your reference:
1. Void Message(int Severity, MSG *message, ...)
{
va_list args;
va_start(args, message)
.....
}
2. function prototype:
Void Message(int, MSG*, ...);

At first, I change function define. but I don't change prototype, the old
prototype is
Void Message();
I think it is right at first, but I found I am wrong. After I change the
prototype,
All the complier is ok.
 
J

Jack Klein

All,

Now I meet a problem, when I use va_start in GCC 3.3.1.
The following is the problem description:
Source Code:

void
Message (severity, message, va_alist)
int severity;
MSG *message;

This type of function definition is completely illegal in standard
C++. Even in C, variadic functions have required prototype
definitions since the first 1989 ANSI standard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top