Boost logo

Boost :

Subject: Re: [boost] [gsoc] Boost.Process done
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-09-13 07:28:49

Ilya Sokolov wrote:
> "Stewart, Robert" <Robert.Stewart_at_[hidden]> wrote:
> >
> > The problem with the suggested approach is that Windows winds up
> > with runtime errors if the child_fileno argument exceeds the
> > range. It would be better to make that a compile time error.
> > The only way to do that is to use a template with the fileno
> > being a template argument.
> enum std_fileno { stdin, stdout, stderr }
> #ifdef _WIN32
> typedef std_fileno fileno;
> #else
> typedef int fileno;
> #endif
> void foo(fileno);
> foo(stdout) // ok
> foo(1) // ok on posix, compile error on windows

That's not bad, but it isn't sufficient. The file number may be generated as a small non-negative integer from various sources, even if it is 0, 1, or 2. The enumerators are initialized with the right values, but other values or integers (int or literals) cannot then be used.

A file_number class could be defined that converts from integer and throws an exception on negative or too-large values. 0, 1, and 2 could be guaranteed to not fail at runtime on POSIX and Windows, of course. Static instances for stdin, stdout, and stderr could be provided to avoid the runtime range check, if they prove valuable.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at