View Issue Details

IDProjectCategoryView StatusLast Update
00019811003.1(2024)/Issue8Base Definitions and Headerspublic2026-05-21 15:00
Reporterlygstate Assigned To 
PrioritynormalSeverityEditorialTypeEnhancement Request
Status NewResolutionOpen 
NameYonggang Luo
Organization
User Reference
Sectionhttps://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_types.h.html#tag_14_70
Page Number0
Line Number0
Interp Status
Final Accepted Text
Summary0001981: Request to define ssize_t as the signed version of size_t
DescriptionCurrently ssize_t is defined as:
ssize_t shall be signed integer types.
The type ssize_t shall be capable of storing values at least in the range [-1, {SSIZE_MAX}].

But the sizeof ssize_t is not explicitly defined.

And for glibc,musl,cygwin newlib, they all defined that sizeof(ssize_t)=== sizeof(size_t)

And maybe because the sizeof ssize_t is not defined clearly. clang did not defined the sizeof of ssize_t well:

https://github.com/llvm/llvm-project/issues/198975


The glibc defined the sizeof ssize_t to be equal to size_t by the following codes:
#if __WORDSIZE == 32
# define __SWORD_TYPE int
#else
# define __SWORD_TYPE long int
#endif

at
https://sourceware.org/git/?p=glibc.git;a=blob;f=posix/bits/types.h;h=33b582a8eabf09aadc093658db82353c288590d2;hb=HEAD#l118

#define __SSIZE_T_TYPE __SWORD_TYPE
at
https://sourceware.org/git/?p=glibc.git;a=blob;f=bits/typesizes.h;h=466dd36681a7364952e49b73067d66174543cffd;hb=HEAD#l60

__STD_TYPE __SSIZE_T_TYPE __ssize_t; /* Type of a byte count, or error. */
at
https://sourceware.org/git/?p=glibc.git;a=blob;f=posix/bits/types.h;h=33b582a8eabf09aadc093658db82353c288590d2;hb=HEAD#l194

#ifndef __ssize_t_defined
typedef __ssize_t ssize_t;
# define __ssize_t_defined
#endif
at
https://sourceware.org/git/?p=glibc.git;a=blob;f=posix/sys/types.h;h=2b524761748fc2e0576e3b86fd5558e8a9ebcb18;hb=HEAD#l108

And the document of __WORDSIZE is:
/* Size in bits of the 'long int' and pointer types. */
#define __WORDSIZE
at
https://sourceware.org/git/?p=glibc.git;a=blob;f=bits/wordsize.h;h=53013a9275c7c81eccb0356ab956eb2688bcf512;hb=HEAD#l7

So basically glibc is already ensure ssize_t is the same size as size_t. Even thoug the command "/* Size in bits of the 'long int' and pointer types. */" is a bit mis-leading.
As sizeof pointer will not always have the same size as size_t.


Desired Actiondefine sizeof ssize_t to be sizeof size_t,

Tagsissue8, issue9, size_t, ssize_t

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2026-05-21 15:00 lygstate New Issue
2026-05-21 15:00 lygstate Tag Attached: issue8
2026-05-21 15:00 lygstate Tag Attached: issue9
2026-05-21 15:00 lygstate Tag Attached: size_t
2026-05-21 15:00 lygstate Tag Attached: ssize_t