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 5 2808
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.
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.
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 characters as possible will be matched.
the regular expression module fails to perform non-greedy matches as
described in the documentation: more than "as few characters as possible"
|
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 their
dtor is called immediately and not at the end of the function. to be able to
use return objects (to avoid copying) i often assign them to a const
reference.
now, casting a const return object from a function to a non-const reference
to this...
|
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 non-word characters from the
string:
// PCRE syntax:
$string = preg_replace("/(+)/", "-", $string);
|
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 that these columns in the unique indexes are truly unique and
don't constitute a collision hazard of any kind.
Now, I personally wouldn't use unique where non-unique would do but I
|
by: Adrian Herscu |
last post by:
Hi all,
In which circumstances it is appropriate to declare methods as non-virtual?
Thanx,
Adrian.
| |
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 to save
it.
I have tried creating the object that I place into the DoDragDrop() by
inheriting the COM interfaces IDropSource and IDataObject with no
luck. If anyone can help I am very much open to suggestions.
Thanks in advance!
|
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 using such dialog box on a non-English Windows
OS (I'm currently testing on Spanish WinXP Professional).
I'm noticing that on non-English Windows OS there are some categories whose
|
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.
So, I tricked my Transparent Non-MDI Child form into my MDI-Container
form via SetParent API as seen here in my VB.NET sample (
http://wuhenry.beigetower.org/position.zip ).
I thought my problems are over, but apprently, even though I...
|
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 to
python-3000@python.org
In summary, this PEP proposes to allow non-ASCII letters as
identifiers in Python. If the PEP is accepted, the following
identifiers would also become valid as class, function, or
variable names: Löffelstiel,...
|
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 the Post:
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/e81cd9d9c2200d74/48c0774eeb3bd998?hl=en&lnk=gst&q=initial+value+of+reference+to+non-const#48c0774eeb3bd998
...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |