std::size_t

Discussion in 'C++' started by Philipp Kraus, Dec 18, 2010.

  1. Hello,

    is there a signed datatype like the unsigned std::size_t? I think
    std::ptrdiff_t is for pointer arithmetics. I need a type with the same
    size but like a signed datatype.

    Thanks

    Phil
    Philipp Kraus, Dec 18, 2010
    #1
    1. Advertising

  2. Philipp Kraus

    Ian Collins Guest

    On 12/19/10 07:31 AM, Philipp Kraus wrote:
    > Hello,
    >
    > is there a signed datatype like the unsigned std::size_t? I think
    > std::ptrdiff_t is for pointer arithmetics. I need a type with the same
    > size but like a signed datatype.


    POSIX defines ssize_t, other systems may also have it. Other wise
    define your own.

    --
    Ian Collins
    Ian Collins, Dec 18, 2010
    #2
    1. Advertising

  3. Philipp Kraus <> wrote:
    > is there a signed datatype like the unsigned std::size_t? I think
    > std::ptrdiff_t is for pointer arithmetics. I need a type with the same
    > size but like a signed datatype.


    Not an answer to your question, but an additional question (related
    to it):

    Does the standard allow sizeof(std::ptrdiff_t) to be different from
    sizeof(std::size_t)?
    Juha Nieminen, Dec 19, 2010
    #3
  4. Philipp Kraus

    Bo Persson Guest

    Juha Nieminen wrote:
    > Philipp Kraus <> wrote:
    >> is there a signed datatype like the unsigned std::size_t? I think
    >> std::ptrdiff_t is for pointer arithmetics. I need a type with the
    >> same size but like a signed datatype.

    >
    > Not an answer to your question, but an additional question (related
    > to it):
    >
    > Does the standard allow sizeof(std::ptrdiff_t) to be different from
    > sizeof(std::size_t)?


    The standard doesn't say anything about that, except that they
    shouldn't be larger than sizeof(unsigned long) unless specifically
    needed.

    If it isn't forbidden, it's probably allowed. :)



    Bo Persson
    Bo Persson, Dec 19, 2010
    #4
  5. On 2010-12-18 20:53:14 +0100, Ian Collins said:

    > On 12/19/10 07:31 AM, Philipp Kraus wrote:
    >> Hello,
    >>
    >> is there a signed datatype like the unsigned std::size_t? I think
    >> std::ptrdiff_t is for pointer arithmetics. I need a type with the same
    >> size but like a signed datatype.

    >
    > POSIX defines ssize_t, other systems may also have it. Other wise
    > define your own.


    Thanks for that answer. I know that POSIX defines this, but my code is
    for cross-plattform, so I can't use the POSIX definition. I think I
    will define my own type

    Phil
    Philipp Kraus, Dec 20, 2010
    #5
  6. On 20 déc, 12:26, Philipp Kraus <> wrote:
    > On 2010-12-18 20:53:14 +0100, Ian Collins said:
    >
    > > On 12/19/10 07:31 AM, Philipp Kraus wrote:
    > >> Hello,

    >
    > >> is there a signed datatype like the unsigned std::size_t? I think
    > >> std::ptrdiff_t is for pointer arithmetics. I need a type with the same
    > >> size but like a signed datatype.

    >
    > > POSIX defines ssize_t, other systems may also have it.  Other wise
    > > define your own.

    >
    > Thanks for that answer. I know that POSIX defines this, but my code is
    > for cross-plattform, so I can't use the POSIX definition. I think I
    > will define my own type


    If your compilers supports some C++0x features, you can define:

    typedef std::make_signed<size_t>::type ssize_t;

    Or roll your own make_signed<>.

    --
    Michael
    Michael Doubez, Dec 20, 2010
    #6
  7. Philipp Kraus

    SaticCaster Guest

    SaticCaster, Jan 3, 2011
    #7
    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. Christopher

    std::size_t

    Christopher, Dec 5, 2003, in forum: C++
    Replies:
    5
    Views:
    12,395
    Andrey Tarasevich
    Dec 8, 2003
  2. JKop
    Replies:
    3
    Views:
    27,033
    Jerry Coffin
    Oct 13, 2004
  3. Jon Rea

    std::vector and size_t

    Jon Rea, Nov 10, 2006, in forum: C++
    Replies:
    3
    Views:
    305
    Andrey Tarasevich
    Nov 10, 2006
  4. Alex Vinokur
    Replies:
    9
    Views:
    762
    James Kanze
    Oct 13, 2008
  5. Alex Vinokur
    Replies:
    1
    Views:
    560
Loading...

Share This Page