question posted on another forum (ptrdiff_t)

Discussion in 'C Programming' started by akshayrao@gmail.com, Nov 30, 2005.

  1. Guest

    , Nov 30, 2005
    #1
    1. Advertising

  2. On 30 Nov 2005 11:22:45 -0800, in comp.lang.c ,
    wrote:

    >could someone point me in the right direction regarding this question??
    >
    >http://groups.google.com/group/programpara/browse_thread/thread/75b58c897f890930


    If you have a question for comp.lang.c. please post it here - its not
    likely that many people will find time to follow a link to google.
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Nov 30, 2005
    #2
    1. Advertising

  3. On 2005-11-30 14:22:45 -0500, said:
    >could someone point me in the right direction regarding this question??
    >
    >http://groups.google.com/group/programpara/browse_thread/thread/75b58c897f890930


    First,

    it seems kind of rude, to me, to post the question elsewhere, and expect
    someone reading the message here to follow a link to find the real question.

    said:
    > 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)??


    Second, by definition, char is always 1 byte; there are no exceptions. (A byte
    may be larger than 8-bits, but sizeof(char) is always equal to 1).

    Third, if you're using Unicode, then the functions in ctype.h (like
    isspace) are
    insufficient.

    > 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 is not pointer
    > arithmetic and we need to scale it??


    I'm not sure what you mean by scaling, but, assuming that all pointers are
    valid, and you don't run off the end of an array, etc.:
    If you increment the pointer x times, then (end - start) == x.

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


    ITYM: while(!isspace((unsigned char)*end))

    >  end++;
    > length = end - start;
    >
    > is this mentioned somewhere in the c std?? if so could someone pt me in the
    > right direction.
    > Thanks.



    --
    Clark S. Cox, III
     
    Clark S. Cox III, Nov 30, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Wahler

    Re: Comparison of ptrdiff_t

    Mike Wahler, Jul 5, 2003, in forum: C Programming
    Replies:
    0
    Views:
    459
    Mike Wahler
    Jul 5, 2003
  2. pete

    Re: Comparison of ptrdiff_t

    pete, Jul 5, 2003, in forum: C Programming
    Replies:
    18
    Views:
    606
    Finny Merrill
    Jul 10, 2003
  3. Stefan Ram

    ptrdiff_t

    Stefan Ram, Dec 3, 2004, in forum: C Programming
    Replies:
    13
    Views:
    892
    Stefan Ram
    Dec 18, 2004
  4. Froefel

    Messages not posted to forum

    Froefel, Jul 20, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    448
    nahid
    Jul 20, 2007
  5. Alexey Verkhovsky

    [Ruby Forum] Forum digest by email

    Alexey Verkhovsky, Sep 22, 2004, in forum: Ruby
    Replies:
    0
    Views:
    439
    Alexey Verkhovsky
    Sep 22, 2004
Loading...

Share This Page