Thread overview
ssize_t
Jun 15, 2005
Vathix
Jun 15, 2005
Sean Kelly
Jun 18, 2005
unknown
Jun 18, 2005
Sean Kelly
Jun 23, 2005
Matthias Becker
Jun 21, 2005
Kevin VR
Jun 25, 2005
Walter
Jun 25, 2005
Mark T
Jun 25, 2005
Vathix
June 15, 2005
How about adding ssize_t to object.d? It's a signed version of size_t. I believe it's fairly common in C.
June 15, 2005
In article <op.sseikqe8kcck4r@esi>, Vathix says...
>
>How about adding ssize_t to object.d? It's a signed version of size_t. I believe it's fairly common in C.

http://svn.dsource.org/projects/ares/trunk/src/ares/std/c/

:p Sean


June 18, 2005
In article <d8ptqf$mep$1@digitaldaemon.com>, Sean Kelly says...
>
>In article <op.sseikqe8kcck4r@esi>, Vathix says...
>>
>>How about adding ssize_t to object.d? It's a signed version of size_t. I believe it's fairly common in C.
>
>http://svn.dsource.org/projects/ares/trunk/src/ares/std/c/
>
>:p Sean

where?



June 18, 2005
In article <d9220a$139o$1@digitaldaemon.com>, unknown says...
>
>In article <d8ptqf$mep$1@digitaldaemon.com>, Sean Kelly says...
>>
>>In article <op.sseikqe8kcck4r@esi>, Vathix says...
>>>
>>>How about adding ssize_t to object.d? It's a signed version of size_t. I believe it's fairly common in C.
>>
>>http://svn.dsource.org/projects/ares/trunk/src/ares/std/c/
>>
>>:p Sean
>
>where?

Oops.  I thought ssize_t was a standard C definition, but it's not.  If it were, it would be in stddef.


June 21, 2005
Vathix wrote:
> How about adding ssize_t to object.d? It's a signed version of size_t. I  believe it's fairly common in C.

According to the D spec's portability guide (http://www.digitalmars.com/d/portability.html) there is this:

<quote>
#  Use size_t as an alias for an unsigned integral type that can span the address space.
# Use ptrdiff_t as an alias for a signed integral type that can span the address space.
</quote>

I don't know why ptrdiff_t is used though. ssize_t does indeed look like a more obvious (and to me more clear) solution.
Maybe it's something that comes from an other language then C?

--
Kevin
June 23, 2005
>>>>How about adding ssize_t to object.d? It's a signed version of size_t. I believe it's fairly common in C.
>>>
>>>http://svn.dsource.org/projects/ares/trunk/src/ares/std/c/
>>>
>>>:p Sean
>>
>>where?
>
>Oops.  I thought ssize_t was a standard C definition, but it's not.  If it were, it would be in stddef.
>

Anyway, who needs ssize_t? you have ptrdiff_t.


June 25, 2005
"Kevin VR" <save.kvr@telenet.be> wrote in message news:d9a7kg$1147$1@digitaldaemon.com...
> I don't know why ptrdiff_t is used though. ssize_t does indeed look like
> a more obvious (and to me more clear) solution.
> Maybe it's something that comes from an other language then C?

ptrdiff_t and size_t are from C.


June 25, 2005
the detailed answer ->
from the GNU C library:
Important Data Types
The result of subtracting two pointers in C is always an integer, but the
precise data type varies from C compiler to C compiler. Likewise, the data type
of the result of sizeof also varies between compilers. ISO defines standard
aliases for these two types, so you can refer to them in a portable fashion.
They are defined in the header file stddef.h.

ptrdiff_t  Data Type
This is the signed integer type of the result of subtracting two pointers. For
example, with the declaration char *p1, *p2;, the expression p2 - p1 is of type
ptrdiff_t. This will probably be one of the standard signed integer types (short
int, int or long int), but might be a nonstandard type that exists only for this
purpose.


size_t  Data Type
This is an unsigned integer type used to represent the sizes of objects. The
result of the sizeof operator is of this type, and functions such as malloc (see
Unconstrained Allocation) and memcpy (see Copying and Concatenation) accept
arguments of this type to specify object sizes.
Usage Note: size_t is the preferred way to declare any arguments or variables
that hold the size of an object.

In the GNU system size_t is equivalent to either unsigned int or unsigned long int. These types have identical properties on the GNU system and, for most purposes, you can use them interchangeably. However, they are distinct as data types, which makes a difference in certain contexts.

For example, when you specify the type of a function argument in a function prototype, it makes a difference which one you use. If the system header files declare malloc with an argument of type size_t and you declare malloc with an argument of type unsigned int, you will get a compilation error if size_t happens to be unsigned long int on your system. To avoid any possibility of error, when a function argument or value is supposed to have type size_t, never declare its type in any other way.

Compatibility Note: Implementations of C before the advent of ISO C generally used unsigned int for representing object sizes and int for pointer subtraction results. They did not necessarily define either size_t or ptrdiff_t. Unix systems did define size_t, in sys/types.h, but the definition was usually a signed type.




June 25, 2005
> ptrdiff_t  Data Type
> This is the signed integer type of the result of subtracting two pointers. For
> example, with the declaration char *p1, *p2;, the expression p2 - p1 is of type
> ptrdiff_t. This will probably be one of the standard signed integer types (short
> int, int or long int), but might be a nonstandard type that exists only for this
> purpose.

I don't believe it will hold the difference between two bit pointers.


import std.stdio;
int main()
{
   //static bit[2] bits = [0, 1];
   static bit* bits = [0, 1];
   ptrdiff_t bitdiff;

   bitdiff = &bits[1] - &bits[0]; // ArrayBoundsError if -bits- is an array.
   writefln("bitdiff = %d", bitdiff);

   writefln("*(&bits[0] + bitdiff) = %d", *(&bits[0] + bitdiff));
   writefln("*(&bits[1] - bitdiff) = %d", *(&bits[1] - bitdiff));

   return 0;
}