X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f Message-ID: <41376655.2A1807EC@yahoo.com> From: CBFalconer <cbfalconer AT yahoo DOT com> 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> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 44 Date: Thu, 02 Sep 2004 19:08:36 GMT NNTP-Posting-Host: 12.76.140.204 X-Complaints-To: abuse AT worldnet DOT att DOT net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1094152116 12.76.140.204 (Thu, 02 Sep 2004 19:08:36 GMT) NNTP-Posting-Date: Thu, 02 Sep 2004 19:08:36 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Egon Eckert wrote: > > compiling and running this code: > > #include <stdio.h> > > 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. At least all three signalled a failure. -- Some useful references: <http://www.ungerhu.com/jxh/clc.welcome.txt> <http://www.eskimo.com/~scs/C-faq/top.html> <http://benpfaff.org/writings/clc/off-topic.html> <http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99) <http://www.dinkumware.com/refxc.html> C-library