From owner-freebsd-hackers Fri May 3 04:50:55 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id EAA21876 for hackers-outgoing; Fri, 3 May 1996 04:50:55 -0700 (PDT) Received: from wdl1.wdl.loral.com (wdl1.wdl.loral.com [137.249.32.1]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id EAA21871 for ; Fri, 3 May 1996 04:50:53 -0700 (PDT) Received: from miles.sso.loral.com (miles.wdl.loral.com) by wdl1.wdl.loral.com (5.x/WDL-2.4-1.0) id AA16141; Fri, 3 May 1996 04:50:23 -0700 Received: by miles.sso.loral.com (4.1/SSO-SUN-2.04) id AA11816; Fri, 3 May 96 07:48:51 EDT Date: Fri, 3 May 1996 07:48:50 -0400 (EDT) From: Richard Toren X-Sender: rpt@miles To: freebsd-hackers@freebsd.org Subject: Re: stdio problem Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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 | ====================================================