Date: Fri, 3 May 1996 07:48:50 -0400 (EDT) From: Richard Toren <rpt@miles.sso.loral.com> To: freebsd-hackers@freebsd.org Subject: Re: stdio problem Message-ID: <Pine.SUN.3.91.960503073715.11811A-100000@miles>
next in thread | raw e-mail | index | archive | help
The "assumption" that 'fd 0 == stdin at entry to main()' is no longer valid! In the classes I teach here at work, this is one of the examples I use about how old shortcuts/standards make for non-portable code and insidious bugs. I learned this from first-hand experience where fileno(stdin) did not equal 0 but rather 1. And this was a program started from the standard csh command line. This happens when a C++ static initializer procedure opens a file before the crt0.o (or it's C++ equivelant) has yet run. In this case, std{in,out,err} are fds n+0, n+1, n+2. The bottom line is "use the system's services to identify the associated fd for stdin and everything else". Times are changing, any good program will eventually be ported somewhere else, and yesterdays assumption will eventually be wrong someday. ==================================================== Rip Toren | The bad news is that C++ is not an object-oriented | rpt@miles.sso.loral.com | programming language. .... The good news is that | | C++ supports object-oriented programming. | | C++ Programming & Fundamental Concepts | | by Anderson & Heinze | ====================================================
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SUN.3.91.960503073715.11811A-100000>