473,406 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

cannot pass objects of non-POD type

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
Jul 22 '05 #1
8 18004

"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.

john
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)>
Jul 22 '05 #3
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.

Jul 22 '05 #4

"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
Jul 22 '05 #5

"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.
Jul 22 '05 #6

"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

Jul 22 '05 #7
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).
Jul 22 '05 #8

"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
Jul 22 '05 #9

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

Similar topics

5
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) {
4
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...
2
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...
2
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...
4
by: Max | last post by:
public class Entity : System.Windows.Forms.Label { .... protected System.Drawing.Point lastMousePosition; .... } public class Flow : Entity { ....
3
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. ...
3
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.
2
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...
0
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...
11
by: Gangreen | last post by:
Hi, 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. A...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.