Speed of pointers vs. speed of arrays/structs

This is a discussion on Speed of pointers vs. speed of arrays/structs within the C Programming forums, part of the General Programming Boards category; Originally Posted by laserlight Could you elaborate? A pointer is of a different type from a pointer to itself, so ...

  1. #31
    Registered User
    Join Date
    Feb 2008
    Posts
    146
    Quote Originally Posted by laserlight View Post
    Could you elaborate? A pointer is of a different type from a pointer to itself, so how can it point to itself unless there is an error in the code?

    I suspect that the example is a strawman to begin with since it seems to deal with a loop index while iterating with a pointer, whereas there is the idiom of using the pointer to iterate directly.
    Not sure, but I think he was point that maybe situation where *p++ = &p, but I think more on it, I don't see anythinkg with sense.

  2. #32
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You would use it as a parameter to functions. There's a couple of examples here:
    http://www.devx.com/tips/Tip/13825

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #33
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,624
    Not sure, but I think he was point that maybe situation where *p++ = &p, but I think more on it, I don't see anythinkg with sense.
    Indeed, because if *p is of type T, then p is of type T*, and &p is of type T**, so that statement assigns a T** to a T, which is clearly a mistake.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. moving pointers to pointers
    By Benzakhar in forum C++ Programming
    Replies: 9
    Last Post: 12-27-2003, 07:30 AM
  3. pointers to pointers within structs
    By Lord_azrael99 in forum C Programming
    Replies: 2
    Last Post: 08-28-2003, 04:29 AM
  4. Pointers pointers pointers....
    By G'n'R in forum C Programming
    Replies: 11
    Last Post: 11-02-2001, 01:02 AM
  5. Pointers pointers pointers...
    By SMurf in forum C Programming
    Replies: 8
    Last Post: 10-23-2001, 04:55 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21