std::size_t

P

Philipp Kraus

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
 
I

Ian Collins

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.
 
J

Juha Nieminen

Philipp Kraus said:
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)?
 
B

Bo Persson

Juha said:
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
 
P

Philipp Kraus

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
 
M

Michael Doubez

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<>.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top