X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: Martin Str|mberg Newsgroups: comp.os.msdos.djgpp Subject: Re: A question about the ferror behavior Date: Mon, 5 Aug 2013 10:16:30 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 49 Message-ID: References: <51E200D7 DOT 1050800 AT gmx DOT de> NNTP-Posting-Host: ftvAZcRvOze4hbePWaim7g.user.speranza.aioe.org X-Complaints-To: abuse AT aioe DOT org User-Agent: tin/1.4.7-20030322 ("Suggestions") (UNIX) (SunOS/5.9 (sun4u)) X-Notice: Filtered by postfilter v. 0.8.2 Bytes: 1708 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Juan Manuel Guerrero wrote: > Please inspect the code snippet below: > #include > int main(void) > { > char buffer[1024]; > FILE *f = fopen("foobar.txt", "w"); Note nNot "r+" nor "w+". > clearerr(f); > if (fgets(buffer, sizeof(buffer), f) == NULL) > printf("EOF encountered before data\n"); > printf("ferror = %s\n", ferror(f) ? "TRUE" : "FALSE"); > printf("feof = %s\n", feof(f) ? "TRUE" : "FALSE"); > return 0; > } > If this code is compiled with djdev203 or djdev204 I get > the following output: > EOF encountered before data > ferror = FALSE > feof = FALSE > If I compile the code on linux I get the following > output: > EOF encountered before data > ferror = TRUE > feof = FALSE It could be argued that there are no EOF indication for files opened only for writing, hence pointless calling ferror() or feof() on such FILE * variables... I don't know what the standard says about that. -- MartinS