Re: iostreams in 2.0

New Message Reply Date view Thread view Subject view Author view

Jim Helman (jimh++at++surreal)
Thu, 30 Nov 95 13:15:27 -0800


> > *Any* application that includes object files or libraries that rely
> > on the construction of static instances of C++ objects must perform
> > the final link with CC or else the objects will not be constructed.
>
> Ah, but the final link doesn't have to be performed be CC, as the code
> following demonstrates:
>
> test.c++:
>
> #include <iostream.h>
> extern "C" { void test_cpp(void); }
> void test_cpp(void)
> {
> Iostream_init tmp;
> cout << "testing" << endl;
> }

In your example, Iostream_init's storage class is automatic (i.e. on
the stack) rather than static. If you move IoStream_init outside of
the routine so that it has to be constructed globally before test_cpp
is invoked, the example dumps core unless the final link is done with
CC. This is what I meant. Actually, I had thought the same applied
to static instantiation with local scope, i.e.

void test_cpp(void)
{
  static Iostream_init tmp;
  ^^^^^^
  cout << "testing" << endl;
}

However this actually does work. SGI's C++ implementation actually
defers construction until the first time the routine is invoked, so
my comment only applies to static global instances.

> Note that the instantiation of the Iostream_init could not have
> been done globally (as CC would do for you).

Perhaps we're saying the same thing.

rgds,

-jim helman

jimh++at++surreal.asd.sgi.com
415/933-1151


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:04 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.