linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* RE: ELDK 3.0 C++ Problem
@ 2004-05-21 16:46 Wells, Charles
  2004-05-21 18:26 ` Mark Chambers
  0 siblings, 1 reply; 8+ messages in thread
From: Wells, Charles @ 2004-05-21 16:46 UTC (permalink / raw)
  To: 'Carlo Parravicini'; +Cc: linuxppc-embedded


Carlo.

> Lost the beer, the code is wrong but the segfaulted is in the "new"
> (checked with a printf before the memset & also with gdb eh eh)

I'll bet _two_ cases of beer that Wolfgang won the beer. The seg. fault is
happening in the memset.

"printf before the memset" is the wrong debugging tool to use here because
the segment fault happens _before_ the printf output gets printed.  Why gdb
didn't show that you got to the memset call is a puzzle.

One thing is sure.  Your program allocates 4 bytes on the heap.  It then
clears those 4 bytes and the 9,996 bytes that follow.  That's _guaranteed_
to mess up the heap.

BTW, give your program a try in Developer Studio on your PC.  You get a
segment fault out of memset.

Regards,
Charlie

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread
* RE: ELDK 3.0 C++ Problem
@ 2004-05-19 21:38 Gosha, Michael (Michael)
  2004-05-19 23:17 ` Wolfgang Denk
  0 siblings, 1 reply; 8+ messages in thread
From: Gosha, Michael (Michael) @ 2004-05-19 21:38 UTC (permalink / raw)
  To: linuxppc-embedded; +Cc: Carlo Parravicini


The problem is with your statement, "new int (1000)". This should be
"new int [1000]". You are telling the compiler to initialize 1 integer
to 1000 instead of allocating 1000 integers. Replace the parens with
brackets and it should work.

Regards,

Michael Gosha

-----Original Message-----
From: owner-linuxppc-embedded@lists.linuxppc.org
[mailto:owner-linuxppc-embedded@lists.linuxppc.org] On Behalf Of
Wolfgang Denk
Sent: Wednesday, May 19, 2004 12:57 PM
To: Carlo Parravicini
Cc: linuxppc-embedded@lists.linuxppc.org
Subject: Re: ELDK 3.0 C++ Problem



In message <200405191757.48552.c.parravicini@sehitaly.com> you wrote:
>
> have anybody problems using ELDK3.0 ppc_8xx-g++ cross-compiler(x86) on

> 'new' function?

What makes you think this is a problem with ELDK's C++ compiler?  Did
you for example try to compile the same program with a native GCC 3.x
C++ compiler on your PC?

> I try to run a stupid program like that on a linux 2.4.4 (previus ELDK

> 2.1) & linux 2.4.24 (ELDK 3.0)

I agree with your rating ;-)

> //=================================================
> #include <iostream>
> #include <string.h>
> int main (int argc, char **argv)
> {
>   int *p = new int (10000);
>   memset ( p, 0, 10000);
>   if (p == NULL)
>    std::cout << "Allocation error\n";
>   else
>    std::cout << "OK.\n";
>
> return 0;
> //=================================================

This program cannot be compiled, there is a '}' missing.

> ppc_8xx-g++ =Wall cpp.cpp -o cpp

This was most definitely NOT the command line you used.

> Both give me a segmentation fault on 'new' execution

What makes you think so? I bet a case of beer that the 'new" returned
just fine, and that your program segfaulted in memset() instead.

Of course you didn't see this, as your test if p is NULL is much  too
late,  and  obviously  you  didn't  bother to run the program under a
debugger.

> Any other have c++ compiling problems or have compiled c++ code
> successfuly?

There are no known C++ problems specific to the ELDK  (i.  e.  except
those that apply to the native version of the same GCC as well).

The problem is not with the ELDK.

Best regards,

Wolfgang Denk

--
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-4596-87  Fax: (+49)-8142-4596-88  Email: wd@denx.de
                  Nail here --X-- for new monitor.


** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread
* ELDK 3.0 C++ Problem
@ 2004-05-19 15:57 Carlo Parravicini
  2004-05-19 17:56 ` Wolfgang Denk
  0 siblings, 1 reply; 8+ messages in thread
From: Carlo Parravicini @ 2004-05-19 15:57 UTC (permalink / raw)
  To: linuxppc-embedded@lists.linuxppc.org


Hi all,

have anybody problems using ELDK3.0 ppc_8xx-g++ cross-compiler(x86) on 'new'
function?
I try to run a stupid program like that on a linux 2.4.4 (previus ELDK 2.1) &
linux 2.4.24 (ELDK 3.0)
//=================================================
#include <iostream>
#include <string.h>
int main (int argc, char **argv)
{
  int *p = new int (10000);
  memset ( p, 0, 10000);
  if (p == NULL)
   std::cout << "Allocation error\n";
  else
   std::cout << "OK.\n";

return 0;
//=================================================

ppc_8xx-g++ =Wall cpp.cpp -o cpp
ldd cpp->
	libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x0ff12000)
	libm.so.6 => /lib/libm.so.6 (0x0fe46000)
	libc.so.6 => /lib/libc.so.6 (0x0fce7000)
	/lib/ld.so.1 => /lib/ld.so.1 (0x30000000)


Both give me a segmentation fault on 'new' execution


The same using a malloc compiled in 'C' mode runs
Previous version of ELDK works fine

Any other have c++ compiling problems or have compiled c++ code successfuly?




email: carlo@sehitaly.com
http://www.sehitaly.com

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-05-21 18:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-21 16:46 ELDK 3.0 C++ Problem Wells, Charles
2004-05-21 18:26 ` Mark Chambers
  -- strict thread matches above, loose matches on Subject: below --
2004-05-19 21:38 Gosha, Michael (Michael)
2004-05-19 23:17 ` Wolfgang Denk
2004-05-19 15:57 Carlo Parravicini
2004-05-19 17:56 ` Wolfgang Denk
2004-05-20 14:02   ` Carlo Parravicini
2004-05-20 16:14     ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).