pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: C portability question

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 that
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.

                                        Greg A. Woods; Planix, Inc.

Home | Main Index | Thread Index | Old Index