Deciding whether time values should be signed or unsigned

Thiago Macieira thiago at kde.org
Mon Aug 25 11:00:25 PDT 2008


On Segunda 25 Agosto 2008 19:42:40 Peter McCurdy wrote:
> I recently filed bug 17289 [0], but it looks like this will need a bit
> of discussion.
>
> As background, I've gotten it into my head to fix all the compiler
> warnings in DBus.  The warnings seem to be increasing over time, since
> there's so many that need to be ignored, and at least some of them
> seem to be complaining about real bugs (e.g. my recently-filed bug
> 17279), so it seems there is actual value to be had in fixing them.
> Of the bulk of the warnings, there's one main issue, mismatched
> signedness in pointers, which in turn has two root causes, signed vs.
> unsigned time values and signed vs. unsigned char*s.  For starters,
> I've just tackled the time values.

You should use time_t, struct timeval, etc. internally, everywhere when 
dealing with the system calls. Don't try to invent your own time value.

I also don't see the need to have sec/usec pairs everywhere. A struct would 
probably be better, and we have "timeval" for that. I understand the aversion 
of using any system headers in files that aren't "sysdep", so we could define 
our own structure.

In the API, you should use signed for the simple reason that some functions 
require a marker value of -1. So be consistent and use signed everywhere.

However, when exporting via D-Bus, you should use dbus_int64_t. There's no 
point in making it unsigned, since the chance of needing dates past the year 
584,554,527,420 is much more remote than those of needing dates in the 1960s.

I understand that the last two points don't apply to the patches you have, but 
they come as indications that signed is preferred.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.freedesktop.org/archives/dbus/attachments/20080825/3e12c23a/attachment.pgp 


More information about the dbus mailing list