This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: linking problem when using "fopen"


On Fri, 2002-04-05 at 10:45, Martin Buck wrote:
> Jonathan Larmour wrote:
> > > Using the non-throwing form of operator new might work:
> > >
> > >         new (std::nothrow) Cyg_StdioStream(...);
> > 
> > I'm afraid I doubt this will work.
> 
> I don't know about this problem here, but wouldn't "new (std::nothrow)"
> be the correct solution anyway?
> 
> IIRC, gcc assumes that the standard new always succeeds if it doesn't
> throw an exception (which it can't in this case due to -fno-exceptions)
> and calls the constructor without checking the return value from new. So
> checking for curr_stream == NULL in fopen.cxx is useless because calling
> Cyg_StdioStream's constructor with a NULL this pointer will most likely
> already have caused a crash.

Yes, good point Martin. However, the class Cyg_StdioStream could
redefine new to use a preallocated heap and keep one slot for the error
case for instance. Anyway, it would not return NULL.

In this particular case, (new not overridden and no C++ exceptions), I
believe that a safe way to do it would first allocate the required space
using "new char [sizeof(...)]", and then if this doesn't return 0 then
call the placement operator new to actually create the object.

Robin



-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]