X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f Message-ID: <41379BE3.CA7CDE00@yahoo.com> From: CBFalconer Organization: Ched Research X-Mailer: Mozilla 4.75 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: scanf: strange behavior? References: <20040902144152 DOT GH6858 AT webhome DOT cz> <41376655 DOT 2A1807EC AT yahoo DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 56 Date: Fri, 03 Sep 2004 02:17:29 GMT NNTP-Posting-Host: 12.76.140.250 X-Complaints-To: abuse AT worldnet DOT att DOT net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1094177849 12.76.140.250 (Fri, 03 Sep 2004 02:17:29 GMT) NNTP-Posting-Date: Fri, 03 Sep 2004 02:17:29 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Brian Inglis wrote: > wrote: >> Egon Eckert wrote: >>> >>> compiling and running this code: >>> >>> #include >>> >>> int main(int, const char**) >>> { >>> char c[2]; >>> printf("%d\n", sscanf("A", "%c%c", c, c + 1)); >>> return 0; >>> } >>> >>> gives: >>> >>> 1 in GNU libc (on Linux) >>> 1 in Borland C++ 3.1 (on DOS) >>> -1 in djgpp >>> >>> It's conformant with the docs: "If input ends, or if there is any >>> input failure before the first item is converted and assigned, `EOF' >>> is returned.", so it's not to be called a 'bug', but... >>> >>> Do you think it's a standard violation, or just a "difference", >>> ie. behavior not specified by POSIX, ANSI or other (involved) >>> authority? >> >> I think DJGPP is correct in returning EOF, because the string ends >> before the scan is complete. The only authority is the C >> standard. I would consider it a library bug on Borland and your >> particular Linux installation of libc. This is better suited to >> comp.lang.c. > > Wrong way round. > >> At least all three signalled a failure. > > GNU "info libc a scanf" and the standard agree that EOF is returned > only if an input failure (terminator or eof, error) occurs before > *any* match, including any literal strings and suppressed assignments, > and only assignments due to matched input are counted in the return > value, excluding %n and suppressed assignments, so scanf returns EOF > only on early input failure, and >= *0* on later input failure, > matching failure, or success of course. I just got around to running it under DJGPP 2.03, and got 1. -- Some similarities between GWB and Mussolini: a) The strut; b) Making war until brought up short: Mussolini: Ethiopia, France, Greece. GWB: Afghanistan, Iraq.