Subject: Re: I'd like to change type of struct rlimit's fields
To: None <jtc@cygnus.com>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: tech-userlevel
Date: 12/08/1994 12:18:26
> I'd like to change the type of a struct rlimit's fields from quad_t
> to a new type rlim_t, which will be defined in <sys/types.h>.
I'm in favor of it (for what that's worth).
I'd like to toss out a remark about more general problem, though. That
is: in cases like rlim_t and off_t, where the exact type is unknown,
how is one supposed to do things like print these out, either for
debugging or for saving in things like text save files? The
traditional thing to do has been to cast to long and use %ld, which
worked since long was the largest type available. But long _isn't_ the
largest type available now, and I can't see any good way for the
application author to deal with the situation.
Should I (as an app author) just do something like have my porting
configuration section under NetBSD have something like
#define LARGE_SIGNED_FMT "%qd"
#define LARGE_UNSIGNED_FMT "%qu"
#define LARGE_SIGNED_CAST (long long int)
#define LARGE_UNSIGNED_CAST (unsigned long long int)
and on a "traditional" system something like
#define LARGE_SIGNED_FMT "%ld"
#define LARGE_UNSIGNED_FMT "%lu"
#define LARGE_SIGNED_CAST (long int)
#define LARGE_UNSIGNED_CAST (unsigned long int)
and then write stuff like
fprintf(debugf,"offset " LARGE_UNSIGNED_FMT ", type %s\n",
LARGE_UNSIGNED_CAST thing->offset, thing->type);
or does anyone have any better suggestions? I don't really like this
one very much, and it'll break if gcc ever allows definition of
arbitrarily large integer types ("typedef __sized_int(128) foo_t;" sort
of thing), in which case there's no a priori way to tell how big the
biggest type in use, or the biggest type printf can handle, is.
der Mouse
mouse@collatz.mcrcim.mcgill.edu