Hi Alex,
On Fri, 19 Aug 2022 at 21:36, Alex Willmer <
al...@moreati.org.uk> wrote:
> typedef int... ino_t;
> struct dirent {
> ino_t d_ino;
> int d_type; // actually __uint8_t in header, on macOS 12
> char d_name[];
> ...;
> };
> can cffi & the compiler figure out the correct integer type for d_type (like they do for ino_t)? Or do I need to declare the exact (possibly platform dependant) type?
>
> Experimentation suggests cffi knows the correct type, but it isn't applied
Right, that's a use case that is not supported at the moment. CFFI
doesn't know the type; it just checks that the size is correct, which
is not the same thing. For example, it doesn't know if the integer
type is signed or unsigned, which is quite important in this case.
It would be possible to find out the exact type for an integer field
of a named struct. But it would not be possible to do it in general.
For example, it becomes harder and harder if the struct has no name,
if the integer type is that of an array field or an "int **field", and
so on. It has been a long time now but I think I tried to come up
with a way that works all the time and failed. That's why the rules
of using "int..." only work in very specific situations. (Note that
just getting the size of anything is much easier in C, because
sizeof(x) does not evaluate the expression 'x'; it would also not be a
problem if we could rely on a gcc extension like typeof(), but it
wouldn't work everywhere.)
A bientôt,
Armin Rigo