From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1d321b3a6b8bcab2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-01-30 19:30:12 PST Path: nntp.gmd.de!newsserver.jvnc.net!darwin.sura.net!news.tulane.edu!tulane!ames!elroy.jpl.nasa.gov!delphi.cs.ucla.edu!not-for-mail From: jmartin@oahu.cs.ucla.edu (Jay Martin) Newsgroups: comp.lang.ada Subject: Re: "Subtract C, add Ada" Date: 30 Jan 1995 19:30:12 -0800 Organization: UCLA Computer Science Dept. Message-ID: <3gkas4$ibs@oahu.cs.ucla.edu> References: <3fo2ot$su2@miranda.gmrc.gecm.com> <1995Jan23.154631.6702@sei.cmu.edu> <3g4p94$g07@cronkite.seas.gwu.edu> <1995Jan29.202418@hobbit> NNTP-Posting-Host: oahu.cs.ucla.edu X-Newsreader: NN version 6.5.0.b3.0 #8 (NOV) Date: 1995-01-30T19:30:12-08:00 List-Id: First there was: Newtons Principia.... then came: Einstein's Theory of Relativity... And Now.... G E T C H A R ()!!! BOM-BOM BOM-BOM BOM-BOM... --------------------------------- For some laughs lets look at the man page for getchar(): NAME getc, getchar, fgetc, getw - get character or integer from stream SYNOPSIS #include int getc(stream) FILE *stream; int getchar() int fgetc(stream) FILE *stream; int getw(stream) FILE *stream; DESCRIPTION getc() returns the next character (that is, byte) from the named input stream, as an integer. It also moves the file pointer, if defined, ahead one character in stream. getchar() is defined as getc(stdin). getc() and getchar() are macros. >> Hee Hee, are we getting a char or an "int"? Well it returns >> an int and then we need to do an implicit conversion back into >> a char. Assuming c is a char in "c = getchar()" then we have >> just lost the ability to check for EOF since we may have read >> a char with value 255 (assuming EOF = -1). Implicit conversions >> rule!!! fgetc() behaves like getc(), but is a function rather than a macro. fgetc() runs more slowly than getc(), but it takes less space per invocation and its name can be passed as an argument to a function. > Macros, ZOOOOOOOM!!!!!! getw() returns the next C int (word) from the named input stream. getw() increments the associated file pointer, if defined, to point to the next word. The size of a word is the size of an integer and varies from machine to machine. getw() assumes no special alignment in the file. RETURN VALUES On success, getc(), getchar() and fgetc() return the next character from the named input stream as an integer. On failure, or on EOF, they return EOF. The EOF condition is remembered, even on a terminal, and all subsequent opera- tions which attempt to read from the stream will return EOF until the condition is cleared with clearerr() (see ferror(3V)). >> Hey, maybe we could use this ferror() thingy to tell the difference >> between EOF and char 255. Well we probably should anyway to detect >> the difference between EOF and failure. Oh, the elegance of it all! getw() returns the next C int from the named input stream on success. On failure, or on EOF, it returns EOF, but since EOF is a valid integer, use ferror(3V) to detect getw() errors. >> Oops! Sorry about that. SYSTEM V RETURN VALUES On failure, or on EOF, these functions return EOF. The EOF condition is remembered, even on a terminal, however, opera- tions which attempt to read from the stream will ignore the current state of the EOF indication and attempt to read from the file descriptor associated with the stream. >> Don't want to restrict the programmer! Damn the torpedos! Full >> steam ahead! Lets here it for SYSTEM V!! SEE ALSO ferror(3V), fopen(3V), fread(3S), gets(3S), putc(3S), scanf(3V), ungetc(3S) WARNINGS If the integer value returned by getc(), getchar(), or fgetc() is stored into a character variable and then com- pared against the integer constant EOF, the comparison may never succeed, because sign-extension of a character on widening to integer is machine-dependent. BUGS Because it is implemented as a macro, getc() treats a stream argument with side effects incorrectly. In particular, getc(*f++) does not work sensibly. fgetc() should be used instead. Because of possible differences in word length and byte ord- ering, files written using putw() are machine-dependent, and may not be readable using getw() on a different processor. >> We don't need these stinking warnings, they are obvious from the >> include file! ------------------------------------------------------------------ Well this is what happens when you let incompetent pinheads design operating system and languages. Of course the clowns in industry and academia standing around drooling at this shit with the look of adoration on their faces doesn't help either. I think I'll go punch a brick wall until my hands bleed. Jay