FILE * / int / in the source code - General Discussion and Assistance - CHDK Forum

FILE * / int / in the source code

  • 4 Replies
  • 1844 Views
*

Offline littlejohn

  • *
  • 35
  • Ixus 860is
FILE * / int / in the source code
« on: 01 / September / 2008, 22:36:09 »
Advertisements
Hi,

In the source code (trunk) of raw_merge.c. (in the function of raw_merge_add_file)
There're some variables declared as "int", which are used as FILE *, such as "fbrawin", "fbrawout", and "fcraw".
Wouldn't it be better to declare those variables to its proper type  ???
although it seems to be working with no problem..

*

Offline dzsemx

  • ****
  • 302
  • [SX40HS][A650][A630]
Re: FILE * / int / in the source code
« Reply #1 on: 02 / September / 2008, 01:09:56 »
in C there are a lot of types which are actually int
so you can use int instead of FILE, if the compiler allows it
« Last Edit: 02 / September / 2008, 01:12:24 by dzsemx »

*

Offline littlejohn

  • *
  • 35
  • Ixus 860is
Re: FILE * / int / in the source code
« Reply #2 on: 02 / September / 2008, 02:53:11 »
OK, I got it.
It is just a little bit weird to me.
Since FILE * is a pointer, IMO it at least has to be handled by an unsigned integer to avoid some casting problem.

*

Offline littlejohn

  • *
  • 35
  • Ixus 860is
Re: FILE * / int / in the source code
« Reply #3 on: 02 / September / 2008, 04:57:12 »
Well, the fopen function is been redefined in the trunk's stdlib.h.
Also, the FILE type is defined to be long int. So there's no problem now.  :D


*

Offline reyalp

  • ******
  • 12105
Re: FILE * / int / in the source code
« Reply #4 on: 08 / September / 2008, 20:17:51 »
Actually, this is a bit inconvenient with code that is written for normal stdio (such as the lua IO lib that I've been working on getting running under chdk).  Since the code uses a FILE * (not FILE by itself), you can't just do a simple #define or typedef (no matter what you do, it will still have the *), and it also gets compared to NULL, which typically has a pointer type.

Is there a reason that an int should be used instead of some opaque pointer type, or is it just historical ?

It seems to me if we are going to make this use the same names as stdio (rather than Fut_) it should behave like stdio as much as possible.

edit:
I'd also be interested to know the difference between the Fut API, Fstream_* and regular stdio functions that appear to exist in the firmware.
« Last Edit: 08 / September / 2008, 23:26:59 by reyalp »
Don't forget what the H stands for.

 

Related Topics