Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » int16_t al_fread16le(ALLEGRO_FILE *f) returns EOF?

This thread is locked; no one can reply to it. rss feed Print
int16_t al_fread16le(ALLEGRO_FILE *f) returns EOF?
Martin Kalbfuß
Member #9,131
October 2007
avatar

Is this even possible when the read value is 16 bit wide? Wouldn't EOF represent a number?

http://remote-lisp.spdns.de -- my server side lisp interpreter
http://www.nongnu.org/gm2/ -- Modula-2 alias Pascal++

Trent Gamblin
Member #261
April 2000
avatar

Ya, I think you're right (and there are some other similar functions that look wrong too).

Martin Kalbfuß
Member #9,131
October 2007
avatar

int32_t al_fread32le(ALLEGRO_FILE *f, bool *ret_success)

doing it right.

But i would prefer

bool al_fread32le(ALLEGRO_FILE *f, int32_t *value);

This way you can do

if (al_fread32le(stream, &number))
{
   ...
}

http://remote-lisp.spdns.de -- my server side lisp interpreter
http://www.nongnu.org/gm2/ -- Modula-2 alias Pascal++

Matthew Leverton
Supreme Loser
January 1999
avatar

I suggested this same thing a while ago. I believe the current solution is (or was) to check via an error function.

I don't particularly like the "ret_success" solution either, although perhaps it's better for the rare times that you don't actually want to use a variable to store the data.

ImLeftFooted
Member #3,935
October 2003
avatar

Can we have both?

Peter Wang
Member #23
April 2000

I suppose "bool al_fread16le(ALLEGRO_FILE *f, int16_t w);" has a certain symmetry with "size_t al_fwrite16le(ALLEGRO_FILE *f, int16_t w);".

Thomas Fjellstrom
Member #476
June 2000
avatar

If its going to return a status, maybe it should probably also be size_t, and report how much it read back. Of course it provides no way to rescue from a short read, so the information would be mostly useless, but it would match the fwriteNNmm functions and the base fread and fwrite functions.

Just an idea.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Go to: