need to be enlightened on pid_t

Discussion in 'C Programming' started by Grocery Clerk, Oct 3, 2004.

  1. I know size_t (used for size of objects) is a 32-bit value on a 32-bit
    system and 64-bit on a 64 bit system. This is explained on Page 29 of
    Unix Network Programming: The Sockets Networking API. Can someone
    please explain to me the reasoning behind pid_t?
     
    Grocery Clerk, Oct 3, 2004
    #1
    1. Advertising

  2. Grocery Clerk

    Jack Klein Guest

    On 2 Oct 2004 19:15:52 -0700, (Grocery Clerk) wrote
    in comp.lang.c:

    > I know size_t (used for size of objects) is a 32-bit value on a 32-bit
    > system and 64-bit on a 64 bit system.


    That may be true on some particular implementations that interest you,
    but no such guarantee or requirement exists in the C language. size_t
    is a typedef for an unsigned integer type, and C specifies that it is
    large enough to hold the size of any object in bytes.

    > This is explained on Page 29 of
    > Unix Network Programming: The Sockets Networking API. Can someone
    > please explain to me the reasoning behind pid_t?


    Nobody here can, because there is no 'pid_t' type defined by the
    standard C language. If this is some extension provided on UNIX, you
    need to ask about it in news:comp.unix.programmer.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Oct 3, 2004
    #2
    1. Advertising

  3. Grocery Clerk

    Malcolm Guest

    "Grocery Clerk" <> wrote
    >
    > I know size_t (used for size of objects) is a 32-bit value on a 32-bit
    > system and 64-bit on a 64 bit system. This is explained on Page 29 of
    > Unix Network Programming: The Sockets Networking API. Can someone
    > please explain to me the reasoning behind pid_t?
    >

    A size_t is the type yielded by the sizeof() operator, and also some
    functions such as strlen(). This means that it must be big enough to hold
    the largest object that the compiler can deal with. Normally this means that
    it will be the same size as the address space of the processor, however
    there is no guarantee (for instance an implementation might choose to
    restrict objects to 64K for efficiency reasons on some architectures).

    A pid_t is a separate type not in the C standard but defined by your Unix
    library. It will hold something that is not a basic type (a number or
    character on which it makes sense to do calculations), and not a memory size
    either. The two reasons for defining a type are to make this clear, so that
    all programmers know that variable x is a p_id and not just an arbitrary
    integer, and so that the underlying system can be changed wthout breaking
    underlying code, for instance we could move to a system where p_ids are
    pointers rather than integer handles in the next release.
     
    Malcolm, Oct 3, 2004
    #3
  4. "Malcolm" <> writes:
    [...]
    > A pid_t is a separate type not in the C standard but defined by your Unix
    > library. It will hold something that is not a basic type (a number or
    > character on which it makes sense to do calculations), and not a memory size
    > either. The two reasons for defining a type are to make this clear, so that
    > all programmers know that variable x is a p_id and not just an arbitrary
    > integer, and so that the underlying system can be changed wthout breaking
    > underlying code, for instance we could move to a system where p_ids are
    > pointers rather than integer handles in the next release.


    <OT>
    As it happens, POSIX requires pid_t to be a signed integer type.
    </OT>

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Oct 3, 2004
    #4
  5. Grocery Clerk

    Fredrik Tolf Guest

    OT: Re: need to be enlightened on pid_t

    On Sat, 2004-10-02 at 19:15 -0700, Grocery Clerk wrote:
    > I know size_t (used for size of objects) is a 32-bit value on a 32-bit
    > system and 64-bit on a 64 bit system. This is explained on Page 29 of
    > Unix Network Programming: The Sockets Networking API. Can someone
    > please explain to me the reasoning behind pid_t?


    This isn't C, of course, but POSIX, so it's really off-topic here.

    The thing is that POSIX likes to define a lot of typedefs to hold
    datatypes that are supposed to be opaque to the programmer, like pid_t,
    uid_t, gid_t, regex_t, socklen_t. These types, while usually defined as
    different primitive integer types, are meant to be opaque, and thus only
    certain operations are defined to work on them -- Usually things like
    comparing to zero of below zero. The programmer may not assume anything
    about their size either (except that returned by sizeof). That way,
    implementors can deal with it in different ways while not breaking
    programs that are compliant with the specified guidelines. For example,
    32-bit Solaris may define a socklen_t to be 32 bits, while 64-bit
    Solaris may define it to be 64 bits. Furthermore, some systems may have
    16-bit UIDs, others 32-bit UIDs, and so on. Some may not even implement
    it as integers, although that's probably rare, if it exists at all.

    Fredrik Tolf
     
    Fredrik Tolf, Oct 4, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TN Bella
    Replies:
    1
    Views:
    2,492
    Edward
    Jun 18, 2004
  2. Teep
    Replies:
    2
    Views:
    776
    Larry Marburger
    Jun 21, 2004
  3. John
    Replies:
    1
    Views:
    415
    John C. Bollinger
    Aug 19, 2004
  4. Marcus Low

    Someone enlightened me

    Marcus Low, Jul 13, 2008, in forum: Python
    Replies:
    0
    Views:
    314
    Marcus Low
    Jul 13, 2008
  5. Marcus Low

    Someone enlightened me

    Marcus Low, Jul 13, 2008, in forum: Python
    Replies:
    1
    Views:
    288
    bukzor
    Jul 13, 2008
Loading...

Share This Page