c pointers (ptrdiff_t)

B

Brytison

can't replace to other site, just here only, post you question at here
better.
 
A

andy_dufresne

sorry abt that.
here's the question:

hi,
i'd a question abt taking the difference between two pointers.
for eg: if you have 2 char pointers pointing to members of an array,
you
advance one till you encounter a space then take the difference between
the two, will give the correct length of the string irrespective of
whether char is represented by 2 bytes (like in unicode)?? i believe it
would give the correct length, because the compiler is responsible for
scaling the difference when one advances a pointer to point to the next
element like ptr++, or is it that pointer difference (subtraction
between two
pointers to members of the same array) is not pointer arithmetic and we
need
to scale it??

eg problem:
Orig string - char *s;
Ptrs, char *start = s, *end = s;
int length;
while(!isspace(*end))
end++;
length = end - start;

is this mentioned somewhere in the c std?? if so could someone pt me in
the right direction.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top