cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: yangtse: curl/docs/examples 10-at-a-time.c, 1.7, 1.8 anyauthput.c, 1.6, 1.7 fopen.c, 1.11, 1.12 ftpuploadresume.c, 1.4, 1.5

From: Jamie Lokier <jamie_at_shareable.org>
Date: Tue, 2 Sep 2008 08:31:03 +0100

Yang Tse wrote:
> I can see the following...
>
> #if defined(_WIN64)
> typedef __int64 INT_PTR, *PINT_PTR;
> [...]
> typedef __int64 LONG_PTR, *PLONG_PTR;
> [...]
> #else
> typedef _W64 int INT_PTR, *PINT_PTR;
> [...]
> typedef _W64 long LONG_PTR, *PLONG_PTR;
> [...]
> #endif
>
> So I insist that for this example anyauthput.c, the only place in the
> whole curl source tree where intptr_t is used, the appropriate
> replacement to use is INT_PTR and not LONG_PTR. Even when long and int
> happen to have the same size here they are different data types.

Since you're hiding it behind the name intptr_t, it really doesn't
matter which you use in the typedef, except on 16-bit Windows.

Traditionally in unix, it's been permitted to convert a data pointer
to "long" and back, which is why so much code does that, and why in
Windows you'd be encourage to substitute LONG_PTR instead.

It's never been particularly traditional to convert to "int" and back.

Modern code should use intptr_t or uintptr_t, since they are standard.
On Windows define intptr_t as LONG_PTR or INT_PTR (doesn't matter on
32/64-bit Windows), and on unix, if there isn't a header defining
them, define them to long and unsigned long respectively.

> File descriptor data type is int for _lseek(), _read(), _fstat(),
> _close() as well as the one returned from _open(). So why should we
> use LONG_PTR instead of INT_PTR ?

Is there any connection at all between file descriptors and pointers?

-- Jamie
Received on 2008-09-02