ptrdiff_t is signed, while size_t is not, but both can safely hold the address of a pointer. How is it possible when half the possible values of ptrdiff_t will be negative, so its capacity must be half of that of size_t when it comes to storing pointers, as pointer adresses can't be negative.

Also, it can't be used as an index of an array to hold a very large no. of elements like say 2^30 as an index of an array is not possiblr with ptrdiff_t as 2^30 is not a valid no. in ptrdiff_t (it will slip into negative ), but it can be done in size_t

Recommended Answers

All 5 Replies

FWIW: On questions like these, I tend to search c.l.c for a while. I'm starting here. If you care to dig while we wait (not that I know whether I'll find a good answer or not).

[edit]One of the better items I've found is this:

[...] ptrdiff_t was created to cope with this problem, e.g., there are machines where int is 32 bit but pointers are wider hence math with them may require more bits to contain the result.

the most annoying thing about ptrdiff_t is that the standard doesn't require that pointer math must be representable within the range of this type, i.e., using it has the potential for having undefined behavior. but no other type is appropriate and has the same potential for ub anyway.

Does anyone have an answer to it ?

I gave you my answer. Feel free to dig. Here's a draft of C89:
http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html

BTW. Bumping posts with "anyone got a new answer" is rather rude and it's getting annoying. [edit]In general, I'm discouraged from answering any more of your questions. It seems that you are just going to ignore it and ask for someone else to answer. I don't know if this little habit of yours really encourages anyone else here to spend even a minute replying.

commented: Very well said! +18

I gave you my answer. Feel free to dig. Here's a draft of C89:
http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html

BTW. Bumping posts with "anyone got a new answer" is rather rude and it's getting annoying. [edit]In general, I'm discouraged from answering any more of your questions. It seems that you are just going to ignore it and ask for someone else to answer. I don't know if this little habit of yours really encourages anyone else here to spend even a minute replying.

There was probably a misunderstanding on my part when u said this:

"FWIW: On questions like these, I tend to search c.l.c for a while. I'm starting here. If you care to dig while we wait (not that I know whether I'll find a good answer or not)."

I thought u meant that u would be starting the search in that group (perhaps by posting a similar question there) and post when u got a good answer. That's why I asked if anyone knew the answer to it.

I never meant to hurt u. I asked others because I never thought u had given your reply, only that u had suggested that I start reading from the site, while u will be checking it somewhere else. I was waiting for ur reply. That's why I never said "Anyone has a new answer ?" but that "Anyone has an answer ?"
( I was waiting for the first answer)

Thanks anyway, for the link.

>I thought u meant that u would be starting the search in that group (perhaps
>by posting a similar question there) and post when u got a good answer.

Wow. I can't really come up with a good response to this. But I still feel the need to express my amazement that not only would you think it, you would actually have the balls to come out and say it as if the world revolves around you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.