473,326 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

size_t or ssize_t

Hi,
I am using size_t and ssize_t . But I am confused about them.

<ssize_t>
typedef int __ssize_t;
typedef __ssize_t ssize_t;

<size_t >
typedef unsigned int size_t;

That is:
ssize_t = int
size_t = unsigned int

I see the range of them are :
int ( ssize_t ) : -32767~32767
unsigned int ( size_t ) : 0~65535

My question is : Is that necessary to use ssize_t ? ( size can be minus
? )

Thanks.

Feb 16 '06 #1
11 39548
"Ro*****@gmail.com" <Ro*****@gmail.com> writes:
I am using size_t and ssize_t . But I am confused about them.

<ssize_t>
typedef int __ssize_t;
typedef __ssize_t ssize_t;

<size_t >
typedef unsigned int size_t;

That is:
ssize_t = int
size_t = unsigned int

I see the range of them are :
int ( ssize_t ) : -32767~32767
unsigned int ( size_t ) : 0~65535

My question is : Is that necessary to use ssize_t ? ( size can be minus
? )


size_t is defined in <stddef.h>; it's an unsigned type, the result of
the sizeof operator. It won't necessarily be unsigned int (it could
be unsigned long, for example), and it will often have a range greater
than 0..65535.

ssize_t is not defined in standard C. It's a POSIX extension, so you
shouldn't use it if you care about absolute portability.

<OFF_TOPIC>
ssize_t, if it's defined, is the signed equivalent of size_t.
Presumably it should be used only if you need to store negative
values. The Open Group Base Specification says it's "Used for a count
of bytes or an error indication."
</OFF_TOPIC>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Feb 16 '06 #2
Ro*****@gmail.com wrote:
Hi,
I am using size_t and ssize_t . But I am confused about them. That is:
ssize_t = int
size_t = unsigned int On your particular machine. Could be something different on
other machines.
I see the range of them are :
int ( ssize_t ) : -32767~32767
unsigned int ( size_t ) : 0~65535

My question is : Is that necessary to use ssize_t ? ( size can be minus
? )

necessary in what context ?

size_t comes from standard C,is an unsigned type used for sizes of objects.

ssize_t comes from posix, is a signed type used for a count of bytes or
an error indication.
Feb 16 '06 #3

Nils O. Selåsdal wrote:
Ro*****@gmail.com wrote:
Hi,
I am using size_t and ssize_t . But I am confused about them.
That is:
ssize_t = int
size_t = unsigned int

On your particular machine. Could be something different on
other machines.


Yes, I see. I'm using a PC with Fedora Core 4.
Thanks
I see the range of them are :
int ( ssize_t ) : -32767~32767
unsigned int ( size_t ) : 0~65535

My question is : Is that necessary to use ssize_t ? ( size can be minus
? )

necessary in what context ?

size_t comes from standard C,is an unsigned type used for sizes of objects.

ssize_t comes from posix, is a signed type used for a count of bytes or
an error indication.


Feb 16 '06 #4
"Roka" <Ro*****@gmail.com> writes:
Nils O. Selåsdal wrote:
Ro*****@gmail.com wrote:
> Hi,
> I am using size_t and ssize_t . But I am confused about them.

> That is:
> ssize_t = int
> size_t = unsigned int

On your particular machine. Could be something different on
other machines.


Yes, I see. I'm using a PC with Fedora Core 4.
Thanks
> I see the range of them are :
> int ( ssize_t ) : -32767~32767
> unsigned int ( size_t ) : 0~65535


Then the maximum value of size_t on your system is almost certainly
2147483647, not 65535.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Feb 16 '06 #5

Keith Thompson wrote:
"Roka" <Ro*****@gmail.com> writes:
Nils O. Selåsdal wrote:
Ro*****@gmail.com wrote:
> Hi,
> I am using size_t and ssize_t . But I am confused about them.

> That is:
> ssize_t = int
> size_t = unsigned int
On your particular machine. Could be something different on
other machines.
Yes, I see. I'm using a PC with Fedora Core 4.
Thanks

> I see the range of them are :
> int ( ssize_t ) : -32767~32767
> unsigned int ( size_t ) : 0~65535


Then the maximum value of size_t on your system is almost certainly
2147483647, not 65535.

Thanks.
But I checked /usr/lib/gcc/i386-redhat-linux/4.0.0/include/stddef.h
size_t is long unsigned int ( 32bit , 0~4294967295 )
and
ssize_t is long ( 32bit, -2147483647~2147483647)

Is that somewhere wrong? ( long unsigned int is NOT euqal to unsigned
long int ? )

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.


Feb 16 '06 #6
"Roka" <Ro*****@gmail.com> writes:
Keith Thompson wrote:
"Roka" <Ro*****@gmail.com> writes:
> Nils O. Selåsdal wrote:
>> Ro*****@gmail.com wrote:
>> > Hi,
>> > I am using size_t and ssize_t . But I am confused about them.
>>
>> > That is:
>> > ssize_t = int
>> > size_t = unsigned int
>> On your particular machine. Could be something different on
>> other machines.
>
> Yes, I see. I'm using a PC with Fedora Core 4.
> Thanks
>>
>> > I see the range of them are :
>> > int ( ssize_t ) : -32767~32767
>> > unsigned int ( size_t ) : 0~65535


Then the maximum value of size_t on your system is almost certainly
2147483647, not 65535.

Thanks.
But I checked /usr/lib/gcc/i386-redhat-linux/4.0.0/include/stddef.h
size_t is long unsigned int ( 32bit , 0~4294967295 )
and
ssize_t is long ( 32bit, -2147483647~2147483647)

Is that somewhere wrong? ( long unsigned int is NOT euqal to unsigned
long int ? )


Oops, my mistake. What I meant to say is that the maximum value of
size_t is 4294967295, not 65535.

(BTW, the minimum value of ssize_t on your system is -2147483648, not
-2147483647.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Feb 16 '06 #7

Keith Thompson wrote:
"Roka" <Ro*****@gmail.com> writes:
Keith Thompson wrote:
"Roka" <Ro*****@gmail.com> writes:
> Nils O. Selåsdal wrote:
>> Ro*****@gmail.com wrote:
>> > Hi,
>> > I am using size_t and ssize_t . But I am confused about them.
>>
>> > That is:
>> > ssize_t = int
>> > size_t = unsigned int
>> On your particular machine. Could be something different on
>> other machines.
>
> Yes, I see. I'm using a PC with Fedora Core 4.
> Thanks
>>
>> > I see the range of them are :
>> > int ( ssize_t ) : -32767~32767
>> > unsigned int ( size_t ) : 0~65535

Then the maximum value of size_t on your system is almost certainly
2147483647, not 65535.

Thanks.
But I checked /usr/lib/gcc/i386-redhat-linux/4.0.0/include/stddef.h
size_t is long unsigned int ( 32bit , 0~4294967295 )
and
ssize_t is long ( 32bit, -2147483647~2147483647)

Is that somewhere wrong? ( long unsigned int is NOT euqal to unsigned
long int ? )


Oops, my mistake. What I meant to say is that the maximum value of
size_t is 4294967295, not 65535.

(BTW, the minimum value of ssize_t on your system is -2147483648, not
-2147483647.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.


Thank you very much.

Feb 16 '06 #8
"Roka" <Ro*****@gmail.com> writes:
Keith Thompson wrote: [...]
Oops, my mistake. What I meant to say is that the maximum value of
size_t is 4294967295, not 65535.

(BTW, the minimum value of ssize_t on your system is -2147483648, not
-2147483647.)

[...]
Thank you very much.


You're welcome.

When you post a followup, please delete any quoted text that isn't
relevant; just leave enough so your followup makes sense on its own.
In particular, don't quote a signature unless you're actually
commenting on it.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Feb 16 '06 #9
Ro*****@gmail.com wrote:
My question is : Is that necessary to use ssize_t ? ( size can be minus
? )

Since ssize_t is not a standard type in C (but size_t is), it would seem
that ssize_t is not necessary.
Feb 16 '06 #10
On 15 Feb 2006 22:22:38 -0800, "Ro*****@gmail.com" <Ro*****@gmail.com>
wrote:
Hi,
I am using size_t and ssize_t . But I am confused about them.

<ssize_t>
typedef int __ssize_t;
Names beginning with __ are reserved for the implementation.
typedef __ssize_t ssize_t;
Why the two step? typedef int ssize_t would work just fine.

<size_t >
typedef unsigned int size_t;
Why are you redefining something that is already defined in a standard
header?

That is:
ssize_t = int
size_t = unsigned int

I see the range of them are :
int ( ssize_t ) : -32767~32767
unsigned int ( size_t ) : 0~65535
Possibly true for your system but not a portable assumption.

My question is : Is that necessary to use ssize_t ? ( size can be minus
? )


If there were an object or type whose size is negative, how much
memory would it occupy? Can any object or type be smaller than char
whose size is guaranteed to by +1.
Remove del for email
Feb 17 '06 #11
Barry Schwarz <sc******@doezl.net> writes:
On 15 Feb 2006 22:22:38 -0800, "Ro*****@gmail.com" <Ro*****@gmail.com>
wrote:
I am using size_t and ssize_t . But I am confused about them.

<ssize_t>
typedef int __ssize_t;


Names beginning with __ are reserved for the implementation.
typedef __ssize_t ssize_t;


Why the two step? typedef int ssize_t would work just fine.

<size_t >
typedef unsigned int size_t;


Why are you redefining something that is already defined in a standard
header?


I think he was quoting from his system's headers.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Feb 17 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: William Xuuu | last post by:
Hi, This's a way of defining size_t and ssize_t in Linux: //"linux/types.h" typedef __kernel_size_t size_t; typedef __kernel_ssize_t ssize_t; //"asm/posix_types.h" typedef unsigned...
2
by: Martin v. Löwis | last post by:
I've been working on PEP 353 for some time now. Please comment, in particular if you are using 64-bit systems. Regards, Martin PEP: 353 Title: Using ssize_t as the index type Version:...
26
by: robertwessel2 | last post by:
In another thread, a poster mentioned the Posix ssize_t definition (signed version of size_t). My initial reaction was to wonder what the point of the Posix definition was when ptrdiff_t was...
12
by: Alex Vinokur | last post by:
Why was the size_t type defined in compilers in addition to unsigned int/long? When/why should one use size_t? Alex Vinokur email: alex DOT vinokur AT gmail DOT com...
39
by: Mark Odell | last post by:
I've always declared variables used as indexes into arrays to be of type 'size_t'. I have had it brought to my attention, recently, that size_t is used to indicate "a count of bytes" and that using...
318
by: jacob navia | last post by:
Rcently I posted code in this group, to help a user that asked to know how he could find out the size of a block allocated with malloc. As always when I post something, the same group of people...
73
by: Yevgen Muntyan | last post by:
Hey, I was reading C99 Rationale, and it has the following two QUIET CHANGE paragraphs: 6.5.3.4: "With the introduction of the long long and extended integer types, the sizeof operator may...
89
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.