[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Does anyone face this problem?
From: |
Guy Harrison |
Subject: |
Re: Does anyone face this problem? |
Date: |
Sat, 16 Oct 2004 00:59:51 GMT |
User-agent: |
KNode/0.7.7 |
Vijay Patil wrote:
> Hi all,
> Im using
> gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-20)
> on 64bit linux server
Could just be me "catching up" (bad power), na...
> 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);
Delphi? C passes Right-to-left tradionally. Forget it (I don't mean delphi)
unless very specific reason (ie: see VCL <-> delphi <-> BCB).
%s = C string
"string" (better std::string)
> return 0;
> }
> -------------------------------------------
>
> When i compile this code i get following compilation
> error
>
> [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.
"std::string" isn't compatible with C string type. It does have a method
though...
printf("%s\n",str.c_str());
...much better...
#include <iostream>
#include <string>
#include <cstdlib>
int
main()
{std::string str ("World");
std::cout << "Hello, Debug out " << str << std::endl;
return EXIT_SUCCESS;
}
> 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.
gcc moves further toward the standard. Lurk on alt.comp.lang.learn.c-c++ for
standard issues. Compiler options: (-ansi -pedantic -W -Wall -Werror) hints
here.
<hint>
AnsiString x("foo");
std::string y;
y = x.c_str();
x = y.c_str();
BCB VCL has trouble handling expection that aren't "Exception" based (they
"escape/abort the GUI" (have your code inherit and rethrow).
</hint>