Hi all,
Im using
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-20)
on 64bit linux server
im trying to compile following code
--------------------sam.cpp---------------------
#include <string>
#include <iostream>
#include <stdarg.h>
using namespace std;
void Write( const char* msg, const char* msg2, ...)
cout <<msg <<" "<<msg2<<endl;
int main()
string str("World");
Write("Hello","Debug out %s" ,str);
return 0;
-------------------------------------------
When i compile this code i get following compilation warning .
[oracle@sahyagiri test]$ g++ sam.cpp
sam.cpp: In function `int main()':
sam.cpp:17: warning: cannot pass objects of non-POD
type `struct std::string'
through `...'; call will abort at runtime
When i run the executable, a.out it fails with Illegal
instruction eror
[oracle@sahyagiri test]$ ./a.out
Illegal instruction
[oracle@sahyagiri test]$
Did any one face this problem, if yes is there any one
workaround to this problem.
i guess this is a issue with compiler gcc 3.2.3
because i tries same this with gcc 2.95, though it
gives warning while compilation, but executable runs
with out any runtime error.
Thanks and Regards
Vijay
8
17963
"Vijay" <vi**********@yahoo.com> wrote in message
news:a6**************************@posting.google.c om...
Hi all,
Im using
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-20)
on 64bit linux server
im trying to compile following code
--------------------sam.cpp---------------------
#include <string>
#include <iostream>
#include <stdarg.h>
using namespace std;
void Write( const char* msg, const char* msg2, ...)
{
cout <<msg <<" "<<msg2<<endl;
}
int main()
{
string str("World");
Write("Hello","Debug out %s" ,str);
No idea what you are trying to do, why pass str to Write when you don't use
str inside Write? Anyway try this
Write("Hello", "Debug out %s", str.c_str());
C strings and C++ strings are not the same.
Jul 22 '05
#
2
Vijay wrote:
[oracle@sahyagiri test]$ g++ sam.cpp
sam.cpp: In function `int main()':
sam.cpp:17: warning: cannot pass objects of non-POD
type `struct std::string'
through `...'; call will abort at runtime
The compiler is giving you a big hint here. You can not
pass arguments of non-POD type to VARARG'd functions.
std::string is a non-POD type.
Varargs has no clue about how to deal with non-POD types
(mostly because it doesn't know about the special
construction/copy/destruction sematics inherit in passing
them to subroutines).
I always theorized that an operator... function should
be invoked to convert to something that ... could handle
for classes. This would be in line with out ... args work
in general (there is a conversion, like integer promotion
etc... that makes things work in general)>
Vijay wrote:
Hi all,
Im using
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-20)
on 64bit linux server
im trying to compile following code
--------------------sam.cpp---------------------
#include <string>
#include <iostream>
#include <stdarg.h>
using namespace std;
void Write( const char* msg, const char* msg2, ...)
{
cout <<msg <<" "<<msg2<<endl;
}
int main()
{
string str("World");
Write("Hello","Debug out %s" ,str);
return 0;
}
-------------------------------------------
When i compile this code i get following compilation warning .
[oracle@sahyagiri test]$ g++ sam.cpp
sam.cpp: In function `int main()':
sam.cpp:17: warning: cannot pass objects of non-POD
type `struct std::string'
through `...'; call will abort at runtime
That just tells it. You cannot pass non-POD types through '...' in C++.
std::string is a non-POD type, so you can't pass it.
When i run the executable, a.out it fails with Illegal
instruction eror
[oracle@sahyagiri test]$ ./a.out
Illegal instruction
[oracle@sahyagiri test]$
The compiler did warn you about that, didn't it?
Did any one face this problem, if yes is there any one
workaround to this problem.
Don't pass non-PODs through variable argument lists. Or more general, don't
use variable argument lists at all. They already were dangerous in C, but
in C++, they are also pretty much useless.
i guess this is a issue with compiler gcc 3.2.3
No, it isn't.
because i tries same this with gcc 2.95, though it
gives warning while compilation, but executable runs
with out any runtime error.
That was just bad luck than.
"Rolf Magnus" <ra******@t-online.de> schrieb im Newsbeitrag
news:ck*************@news.t-online.com...
Vijay wrote:
Don't pass non-PODs through variable argument lists. Or more general,
don't
use variable argument lists at all. They already were dangerous in C, but
in C++, they are also pretty much useless.
I would not say so, even without bothering with printf(...) and friends,
look at
the Loki::Conversion<T1, T2> implementation of Adrei Alexandrescu, where he
shows how nice you can use
SomeType1 Test(...) as a kind of catch all type function. (only at
compiletime of course)
Regards
Michael
"Michael Kurz" <mk***@move-multimedia.com> schrieb im Newsbeitrag
news:41********@e-post.inode.at...
the Loki::Conversion<T1, T2> implementation of Adrei Alexandrescu, where
he shows how nice you can use
Sorry for the typo: meant "Andrei" of course.
"Michael Kurz" <mk***@move-multimedia.com> wrote in message
news:41********@e-post.inode.at...
"Rolf Magnus" <ra******@t-online.de> schrieb im Newsbeitrag
news:ck*************@news.t-online.com...
Vijay wrote:
Don't pass non-PODs through variable argument lists. Or more general,
don't
use variable argument lists at all. They already were dangerous in C, but
in C++, they are also pretty much useless.
I would not say so, even without bothering with printf(...) and friends,
look at
the Loki::Conversion<T1, T2> implementation of Adrei Alexandrescu, where he
shows how nice you can use
SomeType1 Test(...) as a kind of catch all type function. (only at
compiletime of course)
True, this trick is used all over Boost Type Traits (and the rest of Boost) and
I think Andrei is largely responsible. But these functions are never actually
invoked.
Furthermore, IIRC, Andrei's original implementation was actually non-conforming
because it passed user-defined types through ellipses. In order to get a
completely conforming implementation you have to jump through a few more hoops.
See
http://www.boost.org/boost/type_trai...onvertible.hpp
.
Jonathan
Jonathan Turkanis wrote:
Furthermore, IIRC, Andrei's original implementation was actually non-conforming
because it passed user-defined types through ellipses. In order to get a
completely conforming implementation you have to jump through a few more hoops.
User defined types are fine.
It's user defined non-POD types that are not.
The problem is that the variable arg mechanism was never updated
to deal with C++. It's restricted to behavior from C (with the
goofy exception of allowing all the args to a function to be variable
but there's no defined way of extracting such).
"Ron Natalie" <ro*@sensor.com> wrote in message
news:41***********************@news.newshosting.co m...
Jonathan Turkanis wrote:
Furthermore, IIRC, Andrei's original implementation was actually
non-conforming because it passed user-defined types through ellipses. In order to get a
completely conforming implementation you have to jump through a few more
hoops. User defined types are fine.
It's user defined non-POD types that are not.
I should have said 'arbitrary user-defined types.' The type traits templates in
question are meant to be able to handle almost any arguments. (Unfortunately,
they still can't. I believe
is_convertible< noncopyable, noncopyable >::value
still causes a compiler error.)
The problem is that the variable arg mechanism was never updated
to deal with C++. It's restricted to behavior from C (with the
goofy exception of allowing all the args to a function to be variable
but there's no defined way of extracting such).
I understand.
Jonathan
This thread has been closed and replies have been disabled. Please start a new discussion.
Similar topics
by: Jan Pieter Kunst |
last post by:
(apologies if this message is a duplicate -- my news server seems to
have problems)
Greetings,
When using PHP 4, this:
// ex. 1
class A {
function A(&$obj) {
by: Gerhard Pretorius |
last post by:
ON Win 2003 IIS6,
Since yesterday, (12 Aug 2003) for some strange reason, (after installing
WindowsServer2003-KB823980-x86-ENU.exe)
I cannot pass the
Request object to to VB COM DLL.
I have...
|
by: Matthew Louden |
last post by:
When I pass an array as a function parameter, it yields the following
compile error. Any ideas?? However, if I create a variable that holds an
array, and pass that variable to the function...
|
by: Mountain Bikn' Guy |
last post by:
It is known that one cannot pass arguments as ref or out in a
marshal-by-reference class. My problem is that I have a C DLL (and C#
wrapper) that I need to isolate in an AppDomain and then I need...
|
by: Max |
last post by:
public class Entity : System.Windows.Forms.Label
protected System.Drawing.Point lastMousePosition;
public class Flow : Entity
|
by: swb76 |
last post by:
I have a Object Oriented question.
I got two forms - Form1 and Form2. I also got two classes Class1 and
Class2
Form1 has objects Object1 - instance of Class1 and Object2 - instance
of Class2.
|
by: deko |
last post by:
I have a Solution with 3 Projects, representing 3 layers:
App_BL
App_DA
App_UI
All in Namespace APP
UI is a Windows Forms app and BL and DA are class libraries.
|
by: John Kelsey |
last post by:
I am an old, longtime C programmer surprised and confused by an error
message I'm getting from my VS2005 compiler...
"Cannot pass 'Item' as a ref or out argument because it is a 'foreach...
|
by: rote |
last post by:
I have a project i created using TableAdapters(Datasets with .xsd) and
everything works well on my PC.
But when i create a websetup project and deploy it to another server.
I keep getting Error...
|
by:
Gangreen
|
last post by:
I am a Java developper, and now I'm trying to learn C++. I'm very new to the programming language. I'm trying to pass objects to a constructor, which I appear to be doing wrong.
|
by:
veera ravala
|
last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
|
by:
isladogs
|
last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
For other local times, please check World Time Buddy
In...
|
by:
jianzs
|
last post by:
Introduction
Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
|
by:
abbasky
|
last post by:
### Vandf component communication method one: data sharing
Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
|
by:
isladogs
|
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by:
stefan129
|
last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
|
by:
egorbl4
|
last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это
Что это? Что мне с этим делать?
|
by:
davi5007
|
last post by:
Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
|
by:
MeoLessi9
|
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
|