Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > std::size_t

Reply
Thread Tools

std::size_t

 
 
Philipp Kraus
Guest
Posts: n/a
 
      12-18-2010
Hello,

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

Thanks

Phil

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      12-18-2010
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:trdiff_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
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      12-19-2010
Philipp Kraus <> wrote:
> is there a signed datatype like the unsigned std::size_t? I think
> std:trdiff_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:trdiff_t) to be different from
sizeof(std::size_t)?
 
Reply With Quote
 
Bo Persson
Guest
Posts: n/a
 
      12-19-2010
Juha Nieminen wrote:
> Philipp Kraus <> wrote:
>> is there a signed datatype like the unsigned std::size_t? I think
>> std:trdiff_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:trdiff_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


 
Reply With Quote
 
Philipp Kraus
Guest
Posts: n/a
 
      12-20-2010
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:trdiff_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

 
Reply With Quote
 
Michael Doubez
Guest
Posts: n/a
 
      12-20-2010
On 20 déc, 12:26, Philipp Kraus <philipp.kr...@flashpixx.de> 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:trdiff_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

 
Reply With Quote
 
SaticCaster
Guest
Posts: n/a
 
      01-03-2011
Article "About size_t and ptrdiff_t" - http://www.viva64.com/en/a/0050/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57