From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f7344,379448a54fafa5c9 X-Google-Attributes: gidf7344,public X-Google-Thread: 1164f8,14e882a2e94c4748 X-Google-Attributes: gid1164f8,public X-Google-Thread: 110292,dd67877c854c94c4 X-Google-Attributes: gid110292,public X-Google-Thread: 1051a8,dd67877c854c94c4 X-Google-Attributes: gid1051a8,public From: dillon@best.net (Matt Dillon) Subject: Re: What Does DEC Have Left? (was: Current Unpleasantness Resolved) Date: 1997/11/21 Message-ID: <654lek$ajm$1@flea.best.net>#1/1 X-Deja-AN: 291268917 References: <63d177$ri9@flonk.uk.sun.com> <346C4EA7.358C8E67@yes.optus.com.au> <64ia1i$of4$2@joe.rice.edu> <34753FEF.1EB6@mail.dec.com> X-Trace: 880138519 9185 dillon 206.184.139.132 Organization: Best Internet Communications, Inc. - 650 964 BEST Newsgroups: comp.os.vms,comp.sys.dec,comp.sys.intel,comp.sys.mips :In article <34753FEF.1EB6@mail.dec.com>, :Eric D. Osborne wrote: :>Anil Thomas Maliyekkel wrote: :>> :.. :> :>A good ANSI compiler (we have a good one :-) ) will complain if you :>use the wrong parameter types on the calls (and well it should). So, :>if you have code like this :> :> int f; /* file descriptor */ :> int ret_code; /* for return code checking */ :> char buffer[BUFSIZE]; :> /* put in code to open file here */ :> ret_code = read(f, buffer, (size_t) sizeof(buffer)); :> :> :>this will work on ANYTHING that is standards compliant. The problem :>is, people do dumb stuff like this : :> int f; :> int ret_code, size; :> char buffer[BUFSIZE]; :> /* put in code to open file here */ :> ret_code = read(f, buffer, size); :> :>THIS IS BROKEN, because the "size" parameter passed to the read :>call is of the wrong data type. This will, by blind luck, work on most This is not broken. This is why you use prototypes and compile -Wall -Wstrict-prototypes ... to allow the compiler to cast the arguments properly for the call. This is, in fact, one of the primary purposes behind ANSI prototypes and procedure argument specification. To require that exactly the right integer type be passed to a procedure is not good coding practice, it's a pain in the ass and totally non-portable across operating systems. Even with the mandated library call typing, there are hundreds of other libraries out there unrelated to the ANSI spec that one must deal with. Anybody who is not compiling their code prototype-clean is writing seriously broken code. In many cases it's just a matter of making the proper #include's and fixing all the warnings the compiler throws with -Wall -Wstrict-prototypes. If you do that, you are as close to safe as it's possible to write something like: int x = sizeof(buf); int n; char buf[256]; .. n = read(fd, buf, x); or n = read(fd, buf, sizeof(buf)); and have it be perfectly valid code. If you want an example of the clean prototype methodology, take a look at the Diablo source tree at: http://www.backplane.com/diablo/ :>Eric D. Osborne -Matt