[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: C portability question
In article <F1DAF600-313D-48E2-9612-7BCF4D8872C7%planix.ca@localhost>,
Greg A. Woods; Planix, Inc. <woods%planix.ca@localhost> wrote:
>On 11-May-08, at 8:43 PM, Steven M. Bellovin wrote:
>> Thanks, that helps -- but what is the format specifier for off_t?
>> After all, I don't know what type it is. I see your assert(), but
>> strikes me as ugly. I could, I guess, just cast to int64_t, since in
>> this context anything larger is highly unlikely (it's the size of a
>> mail message, and I don't think people are receiving >2^64 bytes of
>> mail in one message...)
>I generally just do the blind cast to int64_t and use %q or PRId64.
>If I were trying to be ultra portable I suppose I would have a compile-
>time test that would report sizeof(off_t) and then use the matching
>PRId* format specifier (or if there are no PRId* defines then I'd cast
>to the matching sized (and signed) native type (int, long, long long,
>etc) along with the matching "native" format specifier.
>So far that's the best portable way I've found to print opaque integer
>types like off_t.
%lld is more portable than %qd since the "quad" specifiers are
being deprecated. %lld will always work for (long long) where %q
will not always work for int64_t. PRId64 will always work for int64_t,
but (long long) could be larger, so it might be better to use.
Main Index |
Thread Index |