[ECOS] Re: uSTL hello world

John Dallaway john@dallaway.org.uk
Wed Sep 9 11:55:00 GMT 2009


Hi Uwe and Jifl

Uwe Kindler wrote:

> If printf is not present in main, then both functions will not get
> called for stdin and stdout and I think I now know why. In the ustl
> package in ofstream.cpp the streams are not created because the streams
> (cout, cin, cerr) are declared this way:
> 
> ifstream cin  (STDIN_FILENO);
> ofstream cout (STDOUT_FILENO);
> ofstream cerr (STDERR_FILENO);
> 
> That means they use the fileno to open the streams - they do not create
> them. But the streams are not present, because no function uses stdout,
> stdin, that means there are no references and the linker throws stdout
> and stdin away. This is the reason why the static constructors of stdout
> and stdin are never get called.
> 
> Here is my proposal to solve this problem. I changed the declaration of
> cout, cin and cerr this way:
> 
> ifstream cin  (((Cyg_StdioStream *)stdin)->get_dev());
> ofstream cout (((Cyg_StdioStream *)stdout)->get_dev());
> ofstream cerr (((Cyg_StdioStream *)stderr)->get_dev());
> 
> This ensures that stdout, stdin and stderr are created. After this
> change cyg_fd_assign() and cyg_fd_alloc() will get called if there is no
> printf function in main.cpp. The call cout << "Hello world!\n" works
> now. I noticed that the message is already printed before cout.flush()
> is called. So it seems cout.flush() is not required if a proper serial
> driver is used. If I use the diagnostic serial driver, then I always
> needed to call cout.flush().
> 
> If you agree to my proposal then I will provide a patch.

Uwe, congratulations on tracking this down. Your analysis makes good sense.

Jifl, is there a preferred way to ensure initialisation of the stdio
streams in the file descriptor table? I note that open() in the file I/O
package uses:

    CYG_REFERENCE_OBJECT(stdin);
    CYG_REFERENCE_OBJECT(stdout);
    CYG_REFERENCE_OBJECT(stderr);

Is this addressing the same issue that we're observing with uSTL?

John Dallaway

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



More information about the Ecos-discuss mailing list