delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/09/02/10:43:21

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Date: Thu, 2 Sep 2004 16:41:52 +0200
From: Egon Eckert <egon AT heaven DOT industries DOT cz>
To: djgpp AT delorie DOT com
Subject: scanf: strange behavior?
Message-ID: <20040902144152.GH6858@webhome.cz>
Mime-Version: 1.0
User-Agent: Mutt/1.5.5.1+cvs20040105i
Sender: Egon Eckert <egon AT webhome DOT cz>
Reply-To: djgpp AT delorie DOT com

Hi,

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?

Thanks,

-- 
Egon Eckert, Heaven Industries, s.r.o.
E-mail: egon AT heaven DOT industries DOT cz

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019