va_list

K

Keith Thompson

ramu said:
Can we intialize va_list to NULL?
ie. va_list = NULL

Probably not. va_list is "an object type suitable for holding
information needed by the macros va_start, va_arg, va_end, and
va_copy"; it's unlikely to be a pointer type.

What are you trying to accomplish?
 
?

=?iso-2022-kr?q?=1B=24=29CHarald_van_D=0E=29=26=0F

Probably not. va_list is "an object type suitable for holding
information needed by the macros va_start, va_arg, va_end, and va_copy";
it's unlikely to be a pointer type.

I have one implementation where va_list is a typedef for char *, and know
of one where it's a typedef for void *. Also, implementations are allowed
to define NULL as 0, which is a valid initialiser for all scalar types. I
wouldn't say we can "probably" not initialise a va_list to NULL, just
that it's not portable and a bad idea even on the systems that do allow
it.
 
R

ramu

Probably not. va_list is "an object type suitable for holding
information needed by the macros va_start, va_arg, va_end, and
va_copy"; it's unlikely to be a pointer type.

What are you trying to accomplish?

--
Keith Thompson (The_Other_Keith) (e-mail address removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Miniss


Sorry. I meant va_list ap=NULL;
Not va_list = NULL;
 
K

Keith Thompson

ramu said:
Sorry. I meant va_list ap=NULL;
Not va_list = NULL;

Please don't quote signatures (the stuff following the "-- " line)
unless you're actually commenting on them.

I assumed that was what you meant; I actually missed the fact that you
assigned a value to a type rather than to a variable.

But again, va_list is not necessarily a pointer type, and assigning a
null value to a va_list object, as far as I can tell, doesn't make any
sense.

And again, what are you trying to accomplish?
 
R

ramu

Please don't quote signatures (the stuff following the "-- " line)
unless you're actually commenting on them.

I assumed that was what you meant; I actually missed the fact that you
assigned a value to a type rather than to a variable.

But again, va_list is not necessarily a pointer type, and assigning a
null value to a va_list object, as far as I can tell, doesn't make any
sense.

And again, what are you trying to accomplish?

Am getting Lint warning saying that variable is not initialized.
So am trying to initialize ap to NULL.
 
P

Peter Nilsson

ramu said:
Am getting Lint warning saying that variable is not
initialized. So am trying to initialize ap to NULL.

va_list ap = { 0 };

You can initialise _any_ object with { 0 }. However, if you're
just doing this to silence one warning, realise that applying
a fix may simply raise an alternative warning.

Apart from fixing actual errors, you shouldn't be letting
implementations (or tools thereof) dictate how you write
your code.

Too many programmers fall into the trap of adding needless
casts because a compiler is beeping at them without it.
Because they haven't checked whether there is an actual
problem with the code, they inadvertently add one thinking
that if the compiler has stopped complaining, the code
must be correct.
 
K

Keith Thompson

ramu said:
Am getting Lint warning saying that variable is not initialized.
So am trying to initialize ap to NULL.

I'm guessing that you're getting a warning when you try to use it, not
on the declaration itself.

Initializing ap to NULL is not the solution to your problem. The way
to initialize ap (an object of type va_list) is to use the va_start
macro. Better yet, you should read the documetation (your textbook or
whatever) rather than just guessing.

Here's an example from the C99 standard:

#include <stdarg.h>
#define MAXARGS 31

void f1(int n_ptrs, ...)
{
va_list ap;
char *array[MAXARGS];
int ptr_no = 0;
if (n_ptrs > MAXARGS)
n_ptrs = MAXARGS;
va_start(ap, n_ptrs);
while (ptr_no < n_ptrs)
array[ptr_no++] = va_arg(ap, char *);
va_end(ap);
f2(n_ptrs, array);
}

If that doesn't help, please post your actual code and the exact text
of any warnings you get.
 
K

Kenneth Brody

Keith said:
Am getting Lint warning saying that variable is not initialized.
So am trying to initialize ap to NULL.

I'm guessing that you're getting a warning when you try to use it, not
on the declaration itself.

Initializing ap to NULL is not the solution to your problem. The way
to initialize ap (an object of type va_list) is to use the va_start
macro. Better yet, you should read the documetation (your textbook or
whatever) rather than just guessing.

Here's an example from the C99 standard:

#include <stdarg.h>
#define MAXARGS 31

void f1(int n_ptrs, ...)
{
va_list ap; [...]
va_start(ap, n_ptrs); [...]
If that doesn't help, please post your actual code and the exact text
of any warnings you get.

Perhaps his lint isn't smart enough to know that va_start() will
initialize ap, rather than pass its value to a function? (Or,
perhaps, he's simply not using it correctly. As you say, actual
code will help determine the "real" problem here.)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 

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,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top