You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by pegasus2000 <pe...@email.it> on 2008/05/07 20:40:04 UTC

ios_base::Init::Init ();

I've compiled with success the first version
of NanoCPP (STDCXX for Nanodesktop). 

So, when I enter this program:

#include <nanodesktop.h>

#include <iostream>

int main()
{
    ndInitSystem ();
    using namespace std;
    
    ios_base::Init::Init ();
    
    cout << "Hello World!";
    return 0;
}
 
I obtain the "Hello world" on the
screen of the PSP. 

But, if I remove the string:

ios_base::Init::Init ();

the system crashes at startup. Is it
a normal behaviour or there's some
option in config.h that I must enable
in order to autoinit any object ?

Thanks
Filippo Battaglia

-- 
View this message in context: http://www.nabble.com/ios_base%3A%3AInit%3A%3AInit-%28%29--tp17111782p17111782.html
Sent from the stdcxx-dev mailing list archive at Nabble.com.


RE: ios_base::Init::Init ();

Posted by pegasus2000 <pe...@email.it>.

I have an idea. Can I send to one of your
developer a copy of the package that will
be included in Nanodesktop ?

So, your developer can see what is wrong 
in the system. 



-- 
View this message in context: http://www.nabble.com/ios_base%3A%3AInit%3A%3AInit-%28%29--tp17111782p17202644.html
Sent from the stdcxx-dev mailing list archive at Nabble.com.


RE: ios_base::Init::Init ();

Posted by Travis Vitek <Tr...@roguewave.com>.
 

>Martin Sebor wrote:
>
>Travis Vitek wrote:
>>  
>> ios_base::Init::Init() is the constructor for the type 
>> ios_base::Init. You probably shouldn't be calling it
>> directly, I'm almost surprised that it compiles. At the
>> very least you should be using it by creating an
>> object of that type so that the destructor is called.
>> 
>> You should not normally have to do this. It should be done 
>> automatically for you at dynamic initialization time.
>
>Right. On most platforms it should happen when the <iostream>
>header is #included. But calling Init() directly is perfectly
>fine and has the same effect as #including <iostream>.

I've never seen a constructor explicitly invoked like

  Type::Type();

but it does seem to work [obviously]. One issue with this is
that it doesn't just invoke the constructor it actually makes
an unnamed temporary, and that temporary's destructor is invoked
immediately.

If you are using an explicit call to the ios_base::Init::Init()
to initialize the streams for the first time, then it is likely
that the destructor that is called will immediately switch the
streams to unbuffered mode.

So technically it doesn't have the same effect as including
<iostream>. :P

Travis


Re: ios_base::Init::Init ();

Posted by Martin Sebor <se...@roguewave.com>.
Travis Vitek wrote:
>  
> 
>> pegasus2000 wrote:
>>
>> I've compiled with success the first version
>> of NanoCPP (STDCXX for Nanodesktop). 
>>
>> So, when I enter this program:
>>
>> #include <nanodesktop.h>
>>
>> #include <iostream>
>>
>> int main()
>> {
>>    ndInitSystem ();
>>    using namespace std;
>>    
>>    ios_base::Init::Init ();
>>    
>>    cout << "Hello World!";
>>    return 0;
>> }
>>
>> I obtain the "Hello world" on the
>> screen of the PSP. 
>>
>> But, if I remove the string:
>>
>> ios_base::Init::Init ();
>>
>> the system crashes at startup. Is it
>> a normal behaviour or there's some
>> option in config.h that I must enable
>> in order to autoinit any object ?
> 
> ios_base::Init::Init() is the constructor for the type ios_base::Init.
> You probably shouldn't be calling it directly, I'm almost surprised that
> it compiles. At the very least you should be using it by creating an
> object of that type so that the destructor is called.
> 
> You should not normally have to do this. It should be done automatically
> for you at dynamic initialization time.

Right. On most platforms it should happen when the <iostream>
header is #included. But calling Init() directly is perfectly
fine and has the same effect as #including <iostream>.

I was hoping we had a test for this (e.g., 27.objects.cpp)
but it doesn't look like we do. We should add one...

> 
> From the looks of it, I'd guess that _RWSTD_NO_STATIC_IOSTREAM_INIT is
> getting defined somewhere. I peeked at my config.h and the config tests
> and I don't see that macro anywhere. Do you define this macro somewhere?

To add to what Travis said: the area of iostream initialization
is tricky. We do it one of three ways, depending on the OS and
compiler. For gcc, std::cin, std::cout, std::cerr, and std::clog
(and their wide equivalents) are declared as references to POD
objects defined in iostream.cpp and lazily initialized in the
first call to ios::Init::Init(). The <iostream> header defines
a static object on type ios::Init whose ctor is responsible
for this initialization. From your description it sounds as
though this object's ctor doesn't run before the inserter is
entered in your program. You need to figure out why :) Let
us know how it goes.

Martin


RE: ios_base::Init::Init ();

Posted by Travis Vitek <Tr...@roguewave.com>.
 

>pegasus2000 wrote:
>
>I've compiled with success the first version
>of NanoCPP (STDCXX for Nanodesktop). 
>
>So, when I enter this program:
>
>#include <nanodesktop.h>
>
>#include <iostream>
>
>int main()
>{
>    ndInitSystem ();
>    using namespace std;
>    
>    ios_base::Init::Init ();
>    
>    cout << "Hello World!";
>    return 0;
>}
> 
>I obtain the "Hello world" on the
>screen of the PSP. 
>
>But, if I remove the string:
>
>ios_base::Init::Init ();
>
>the system crashes at startup. Is it
>a normal behaviour or there's some
>option in config.h that I must enable
>in order to autoinit any object ?

ios_base::Init::Init() is the constructor for the type ios_base::Init.
You probably shouldn't be calling it directly, I'm almost surprised that
it compiles. At the very least you should be using it by creating an
object of that type so that the destructor is called.

You should not normally have to do this. It should be done automatically
for you at dynamic initialization time.

>From the looks of it, I'd guess that _RWSTD_NO_STATIC_IOSTREAM_INIT is
getting defined somewhere. I peeked at my config.h and the config tests
and I don't see that macro anywhere. Do you define this macro somewhere?

Travis

>
>Thanks
>Filippo Battaglia
>