From: Holger Kiehl <Holger.Kiehl@dwd.de>
To: Glynn Clements <glynn@gclements.plus.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: Unsigned off_t?
Date: Tue, 26 Jul 2005 07:38:29 +0000 (GMT) [thread overview]
Message-ID: <Pine.LNX.4.61.0507260638110.22613@praktifix.dwd.de> (raw)
In-Reply-To: <17125.51475.763052.283552@cerise.gclements.plus.com>
On Tue, 26 Jul 2005, Glynn Clements wrote:
>
> Holger Kiehl wrote:
>
>> I would like to have an unsigned off_t, what is the best and portbale way
>> to define this? Currently I use the following code:
>>
>> #if SIZEOF_OFF_T == 4
>> typedef unsigned long u_off_t;
>> #else
>> typedef unsigned long long u_off_t;
>> #endif
>>
>> SIZEOF_OFF_T is returned from the gnu autoconfig tools.
>>
>> Is this the correct way of doing this?
>
> There isn't any "correct" way of doing it.
>
>> Or is there some better more portable way?
>
> Using the types from stdint.h (uint32_t, uint64_t etc) would be more
> portable than making assumptions about the sizes of "long", "long long"
> etc.
>
So a solution with C99 and stdint.h could look as follows:
#ifdef HAVE_STDINT_H
# if SIZEOF_OFF_T == 4
typedef uint32_t u_off_t;
# else
typedef uint64_t u_off_t;
# endif
#else
# if SIZEOF_OFF_T == 4
typedef unsigned long u_off_t;
# else
typedef unsigned long long u_off_t;
# endif
#endif
The problem I have with this is how do I use this with printf() or fprintf()?
What do I use: %u, %lu or %llu? Does C99 provide a solution here?
> Alternatively:
>
> #if SIZEOF_OFF_T == SIZEOF_INT
> typedef unsigned int off_t
> #elif SIZEOF_OFF_T == SIZEOF_LONG
> typedef unsigned long off_t
> #elif SIZEOF_OFF_T == SIZEOF_LONG_LONG
> typedef unsigned long long off_t
> #endif
>
Same problem here as well, how to use this with printf()?
Besides, what do I use for uint64_t in printf()?
> Out of curiosity, why do you want an unsigned off_t anyhow?
>
I use it to store the number of bytes I have send to a certain host.
If this is unsigned there is no need to worry about an overflow and I can
always just add each file size transmitted. Just when I want to calculate
the transfer rate I need to watch out for an overflow.
Thanks,
Holger
next prev parent reply other threads:[~2005-07-26 7:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-25 8:47 Unsigned off_t? Holger Kiehl
2005-07-25 8:53 ` Jeff Woods
2005-07-25 9:00 ` Holger Kiehl
2005-07-26 5:24 ` Glynn Clements
2005-07-26 7:38 ` Holger Kiehl [this message]
2005-07-26 16:53 ` superblock & inode's Nanakos Chrysostomos
2005-07-26 16:59 ` Robert P. J. Day
2005-07-27 5:21 ` sumit kalra
2005-07-27 7:24 ` Glynn Clements
2005-07-27 18:53 ` Nanakos Chrysostomos
2005-07-27 7:23 ` Unsigned off_t? Glynn Clements
2005-07-27 20:09 ` Holger Kiehl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.61.0507260638110.22613@praktifix.dwd.de \
--to=holger.kiehl@dwd.de \
--cc=glynn@gclements.plus.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).