Email List: Xaustin-group-lX
[All Lists]

Re: Comments on XBDd5 ERN 322

To: yyyyyyyyyyyyyy@xxxxxxxxxxxxx
Subject: Re: Comments on XBDd5 ERN 322
From: Paul Eggert <yyyyyy@xxxxxxxxxxx>
Date: Tue, 13 Mar 2001 14:32:45 -0800 (PST)
References: <UTC200103131955.UAA179240.aeb@vlet.cwi.nl>
> Date: Tue, 13 Mar 2001 20:55:08 +0100 (MET)
> From: yyyyyyyyyyyyyyy@xxxxxx
> 
> It seems to me that a routine like
> void outpid(pid_t p) {...}
> prints a pid without making assumptions on the size of a pid.

Something like that 'outpid' can be made to work, and I've done it
myself for off_t (several times :-).  But it is a pain to maintain and
use such routines.  Even assuming outpid is entirely bug-free (which
your wasn't -- it failed if -p overflowed), I cannot recommend to
application writers that they write code like this:

       printf(_("process ID = "));
       outpid(getpid());
       printf(_(", parent process ID = "));
       outpid(getppid());
       printf("\n");

where _() is the usual gettext operation.  Code like that is painfully
hard to write, read, and maintain.  Instead, application writers
should use code like this:

       printf(_("process ID = %ld, parent process ID = %ld\n",
              (long)getpid(), (long)getppid());

This is much easier to write and maintain, is much more reliable, and
works on all current platforms.

Once C99 can be assumed, application writers can replace the above
code with this:

       printf(_("process ID = %jd, parent process ID = %jd\n",
              (intmax_t)getpid(), (intmax_t)getppid());

This will work even on (currently hypothetical) platforms where pid_t
is wider than long.

This gradual approach avoids the 'outpid' porting hassle entirely, and
it's by far the most practical transition strategy for supporting
pid_t and other similar types that new standard allows to be wider
than long.  If we recommend any transition strategy, we should
recommend this one.

(The above discussion assumes pid_t is an integer type.  That's OK in
practice, as no actual implementations use floating-point pid_t.)

<Prev in Thread] Current Thread [Next in Thread>