473,569 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 39614
"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_Keit h) 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.c om 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.c om 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.c om 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_Keit h) 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.c om 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~2147 483647)

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

--
Keith Thompson (The_Other_Keit h) 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.c om 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~2147 483647)

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_Keit h) 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.c om 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~2147 483647)

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_Keit h) 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_Keit h) 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.c om 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

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

Similar topics

7
52670
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 int __kernel_size_t;
2
1875
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: $Revision: 42333 $
26
6681
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 already defined as such. I got the idea that ptrdiff_t had to be the same size as size_t from Plauger's "The Standard C Library," where he states "......
12
10690
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 http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn
39
7999
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 it otherwise is confusing. I also thought that size_t could be signed but it seems I was wrong on that one. So if you were to see code iterating...
318
12799
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 started to try to find possible errors, a harmless passtime they seem to enjoy. One of their remarks was that I used "int" instead of "size_t"...
73
7373
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 yield a value that exceeds the range of an unsigned long." 6.5.6: "With the introduction of the long long and extended integer
89
5670
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 right thing to use for every var that holds the number of or size in bytes of things. * size_t should only be used when dealing with library functions.
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.