Results 1 to 4 of 4

Thread: FAQ is outdated

  1. #1

    Default FAQ is outdated

    Hi.
    http://clanlib.org/docs/clanlib-2.1/overview/faq.htm
    Under "Programming issues", it says you should inherit CL_ClanApplication but that's no longer true.

    Also, it talks about CL_ConsoleWindow::redirect_stdio() which is no longer available (why, btw? it was nicer than having to use CL_Console::write_line).
    Last edited by logixoul; 05-22-2010 at 11:58 AM.

  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    Hehe, yes, the FAQ unfortunately lacks an editor.

    Regarding redirect I/O, that feature was removed simply because it couldn't be implemented safely. It used a hack where it reopened stdin, but this caused various problems with standard libraries.

    If you prefer a different API than CL_Console::write_line you can still do that. It just requires that you use the official classes in the standard C++ library. Obviously I don't agree that this API is better (if I had, I would not have coded CL_Console ) but luckily ClanLib doesn't force you to use a part you don't like.

  3. #3

    Default

    Hey there,
    I hadn't seen your reply.

    Hehe, yes, the FAQ unfortunately lacks an editor.
    Ah, I see it's in wiki format now. Cool!
    I removed the question from there as it's not relevant to the latest ClanLib anyway (since CL_ClanApplication is now optional).

    If you prefer a different API than CL_Console::write_line you can still do that. It just requires that you use the official classes in the standard C++ library.
    That's actually not true, at least on my system.
    • In a non-ClanLib app, when I print to cout the text goes to the "output" pane in the VS debugger (or to the commandline, if I launched the app from there).
    • In a ClanLib app with a CL_ConsoleWindow instantiated, calling CL_Console::write_line prints only to CL's console window (bad) and printing to cout does nothing (also bad).
    • In a ClanLib app without a CL_ConsoleWindow instantiated, neither cout nor CL_Console::write_line do anything.

    If you can't make CL_Console::write_line reliably print to VS's "output" pane (i.e. stdout), that's OK (though I think it's easy).
    If you can't make cout reliably print to ClanLib's console window, that's also OK.
    But at least, cout should work! It should print to VS's "output" pane, but it does nothing. Any ideas about that?

  4. #4
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    Most of your complaints here are related to the Standard C++ library and not things caused by ClanLib, but I'll try to explain why things are like they are (my version of it).

    The iostreams design assumes that the platform being used resembles Unix and its way of doing things. In particular, it assumes that stdin, stdout and stderr are sent to a console window when an application starts. The standard library therefore opens a file handle to each of the three and keeps that file handle internally until your application is closed. There are no official APIs in the standard C++ library that enables you to redirect or reopen cout, cerr or cin.

    Unfortunately, for reasons I do not know, Microsoft decided to change this basic principle for Windows applications. When you compile a Windows application, you tell the linker whether you want to compile it for the "Console" subsystem or the "Windows" subsystem.

    If you pick the Console option, Windows will automatically create a console window when your application is launched and stdin+stdout+stderr will work exactly as you expected and both CL_Console and cout will write to the same destination. If you launch your app from a console, it will even reuse that console making it all like in the good old days.

    But, if you pick the Windows option, there will not be created any console window and stdin+stdout+stderr will all point to null. Therefore, cout will not print to anything at all. CL_ConsoleWindow in ClanLib calls the Win32 function AllocConsole to create a console window which then attempts to redirect stdout+stderr+stdin to this new console window. Unfortunately this does not work with the standard C++ iostreams because they already made a copy of the old handle and since there is no way to tell it to reopen it, cout will continue to write to absolutely nowhere. There is nothing ClanLib can do about this unfortunate behavior - the limitation is in the C++ iostreams and/or Microsoft's implementation of it.

    So why does cout end up in your debuggers output window? I actually didn't know about that feature, but basically something inside Microsoft's implementation detects that it is being debugged and then writes the cout data to the debugger instead.

    I cannot change the behavior of cout for the reasons stated above, but it is trivially easy for me to change CL_Console to write to the debugger as well. All it requires is a call to IsDebuggerPresent+OutputDebugString in CL_Console::write after the call to WriteConsole.

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •