0

I know that uintptr_t and intptr_t are some abstract integer types capable to hold any void pointer.

The following type designates a signed integer type with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer: intptr_t The following type designates an unsigned integer type with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer: uintptr_t These types are optional.

As I understand they hold some abstract integer values and its arithmetic makes a little or no sense in the C standard understanding.

example:

//assumptions:
//start & end are referencing the same array or next element past the end of the array and end - start >= 0
size_t objsize(const void *restrict start, const void *restrict end)
{
    return (size_t)((uintptr_t)end - (uintptr_t)start);
}

Most known to me implementation it will return the difference in bytes, but I think is implementation defined (or even undefined).

Am I right or wrong? Does the arithmetic of those types give any meaningful information?

0___________
  • 47,100
  • 4
  • 27
  • 62
  • 1
    I think this was asked billion times on this site – Language Lawyer Feb 10 '22 at 23:10
  • @LanguageLawyer then enlighten me and show the dupe which answers this particular question instead of posting useless comments. Find the dupe which answers the question - click on `close` and select the `Duplicate` – 0___________ Feb 10 '22 at 23:12
  • https://stackoverflow.com/questions/38442017/is-there-a-defined-way-to-do-pointer-subtraction-in-c11 https://stackoverflow.com/questions/61757409/is-calculating-address-difference-undefined-behaviour?rq=1 https://stackoverflow.com/questions/64740928/can-two-implementation-defined-identical-expressions-give-different-results Actually, it was really hard to find them. – KamilCuk Feb 10 '22 at 23:14
  • @KamilCuk - I closed the question – 0___________ Feb 10 '22 at 23:16
  • plus https://stackoverflow.com/questions/64861886/is-casting-a-pointer-to-intptr-t-doing-arithmetic-on-it-and-then-casting-back – Language Lawyer Feb 10 '22 at 23:17
  • @0___________ why'd they ban you? – samuelbrody1249 Feb 15 '22 at 02:32

0 Answers0