473,487 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

non-POD type in call to va_start

Hi,

I have the following program:

#include <stdarg.h>

class A {
public:
A() { }
}

void f(A a,...) {
va_list l;
va_start(l,a);
// ...
va_end(l);
}

When I try to compile this program (using gcc), the compiler moans
about the non-POD type in the call to va_start() and threatens to abort
at runtime. Having checked the C-spec, this seems reasonable. What I'm
looking for is some kind of work-around. Is there any way I can get
this work (preferably without changing f() to take an A* argument)? Any
suggestions would be greatly appreciated (even using macroes).

Thanks in advance,
Ross

Aug 22 '06 #1
5 2795
Ross wrote:
Hi,

I have the following program:

#include <stdarg.h>

class A {
public:
A() { }
}

void f(A a,...) {
va_list l;
va_start(l,a);
// ...
va_end(l);
}

When I try to compile this program (using gcc), the compiler moans
about the non-POD type in the call to va_start() and threatens to abort
at runtime. Having checked the C-spec, this seems reasonable.
It does? There are no other types than POD in C. Or did you mean the C++
spec?
What I'm looking for is some kind of work-around. Is there any way I can
get this work (preferably without changing f() to take an A* argument)?
Any suggestions would be greatly appreciated (even using macroes).
Well, variable argument lists cannot be used with non-POD types. I don't
think there is a workaround to get it do what you want.

Aug 22 '06 #2
Rolf Magnus wrote:
Ross wrote:
Hi,

I have the following program:

#include <stdarg.h>

class A {
public:
A() { }
}

void f(A a,...) {
va_list l;
va_start(l,a);
// ...
va_end(l);
}

When I try to compile this program (using gcc), the compiler moans
about the non-POD type in the call to va_start() and threatens to abort
at runtime. Having checked the C-spec, this seems reasonable.

It does? There are no other types than POD in C. Or did you mean the C++
spec?
Yes, I meant the C++ spec. Sorry about the typo.

Aug 22 '06 #3
void f(A a, int nDummy,...) {

You can use a dummy integer as the identifier of the rightmost named
parameter. Pass this nDummy to the va_start macro. I think this should
work. (Also the non-PODs should not be passed as a variable argument to
this function.)

Amir Kamerkar

Aug 22 '06 #4


Rolf Magnus wrote:
Ross wrote:
>Hi,

I have the following program:

#include <stdarg.h>

class A {
public:
A() { }
}

void f(A a,...) {
va_list l;
va_start(l,a);
// ...
va_end(l);
}
...
>What I'm looking for is some kind of work-around. Is there any way I can
get this work (preferably without changing f() to take an A* argument)?
Any suggestions would be greatly appreciated (even using macroes).

Well, variable argument lists cannot be used with non-POD types. I don't
think there is a workaround to get it do what you want.
Well, the "non-POD" restriction does indeed apply to the arguments that
are passed as _variable_ ones (i.e. correspond to the '...' portion of
parameter declaration list), but I don't see anything in the standard
that would also extend this requirement to the explicitly declared
parameters, including the one used in 'va_start'. Am I missing something?

--
Best regards,
Andrey Tarasevich

Aug 22 '06 #5

Andrey Tarasevich wrote:
Rolf Magnus wrote:
Ross wrote:
Hi,

I have the following program:

#include <stdarg.h>

class A {
public:
A() { }
}

void f(A a,...) {
va_list l;
va_start(l,a);
// ...
va_end(l);
}
...
What I'm looking for is some kind of work-around. Is there any way I can
get this work (preferably without changing f() to take an A* argument)?
Any suggestions would be greatly appreciated (even using macroes).
Well, variable argument lists cannot be used with non-POD types. I don't
think there is a workaround to get it do what you want.

Well, the "non-POD" restriction does indeed apply to the arguments that
are passed as _variable_ ones (i.e. correspond to the '...' portion of
parameter declaration list), but I don't see anything in the standard
that would also extend this requirement to the explicitly declared
parameters, including the one used in 'va_start'. Am I missing something?
As I understood it, the argument passed to va_start() should have the
type that results if you were to pass an argument of that type to an
ellipsis. Therefore, it can't be a non-POD type because it's undefined
to pass a non-POD type to an ellipsis. I don't have my copy of the spec
to hand, though, so I could be wrong.

Ross

Aug 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
4395
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
5
3724
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
1
6882
by: Markus Ernst | last post by:
Hi I wrote a function that "normalizes" strings for use in URLs in a UTF-8 encoded content administration application. After having removed the accents from latin characters I try to remove all...
4
5268
by: bwmiller16 | last post by:
Guys - I'm doing a database consistency check for a client and I find that they're building unique indexes for performance/query reasons where they could be using non-unique indexes. Note...
32
4464
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
4
3033
by: Dave | last post by:
I need to add the ability to drag from a Windows Form and drop into a non dotNet application. For example, having a generated image in my app that I wish to drag out into explorer as a friendly way...
0
2035
by: Christopher Attard | last post by:
Hi, I need to create a dialog like the 'Add Counters' dialog box in perfmon. I'm using the System.Diagnostics namespace class in .NET and I've managed to do it. The problem arises when I'm...
0
4459
by: Henry Wu | last post by:
Hi, I am aware that TransparencyKey only works with top-level forms or Non-MDI Child Forms, if one tries to set the opacity or transparencykey property to a MDI-Child form, it will have no effect....
399
12626
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
13
18893
by: asm23 | last post by:
Hi,I need some help to clarify the warning "initial value of reference to non-const must be an lvalue". I'm searching in this groups to find someone has the same situation like me. I found in...
0
7106
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5442
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.