Thread: Why pointers? (The answer)

  1. #31
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I completly agree that if a function name indicates that a change will take place then references are perfectly ok.

    Personally I don't follow his advice on the matter and tend to use references, but thats just me. However I do understand what he is saying and why he gave that advice.

  2. #32
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    [going for another page of this thread]

    Sang-drax's swap() code brought back memories of an "argument" I had with Prelude........she won.

    gg

  3. #33
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Doesn't she usally win?

  4. #34
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Sang-drax's swap() code brought back memories of an "argument" I had with Prelude........she won.
    Does this mean that I won't have to go through the whole thing again, but with Sang-drax this time? Or am I doomed to be the "Undefined Behavior Gestapo"?


    It's for your own good, dammit! Now get your butts into Auchwitz (Prelude style) and start analyzing algorithms.
    Last edited by Prelude; 09-03-2004 at 07:58 PM.
    My best code is written with the delete key.

  5. #35
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    I find that statement aesthetic, that's all. I wouldn't want to use it. In fact, I wouldn't want to define my own swap function at all, since we have std::swap.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  6. #36
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I find that statement aesthetic, that's all.
    Sure, it looks cute, but the behavior is undefined. You can write an XOR swap correctly using comma operators and still get the one-liner feel if you want:
    Code:
    void swap ( int& a, int& b )
    {
      a ^= b, b ^= a, a ^= b;
    }
    Now it's just a stylistic and obscurity issue rather than a "you're totally wrong" issue.

    >In fact, I wouldn't want to define my own swap function at all, since we have std::swap.
    True, but many beginners end up writing their own and it's up to us to set a good example.
    My best code is written with the delete key.

  7. #37
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Quote Originally Posted by Hunter2
    P.S. I still like references better, just 'cause I'm lazy and find the * button incredibly hard to reach
    Are you using a different keyboard layout? Because I could've sworn the * was next to the & on my keyboard.

  8. #38
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Assuming you're using the most common QWERTY layout, & is actually further from the right shift than *.

  9. #39
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Frobozz, bumping threads is somewhat frowned upon here.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  10. #40
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>& is actually further from the right shift than *.
    Bump aside, I was referring to the fact that you need to dereference the pointer to use it (unless, as has been suggested, you use a pointer and then create a reference to the dereferenced pointer). And in some cases, you have to put the dereference in (), which is also annoying and hard to read.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  11. #41
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Before it gets closed

    Assuming you're using the most common QWERTY layout, & is actually further from the right shift than *.
    But * is done using the middle finger and the & is done using the index finger which most hunt and peckers use

    Of course I use my middle for & a lot but I don't claim to have good form.

  12. #42
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Actually I use the index finger for * too. Better reach. But in some cases, I actually use rightshift and the left hand to press the button (don't ask me why), so & is really closer than *.
    [edit]And besides, it's not good form to use the same hand for shift and a key anyway. You're supposed to use the shift for the opposite hand that you're pressing the key with So if you use proper form, the & and * should be very similar in distance.[/edit]
    Last edited by Hunter2; 10-13-2004 at 05:18 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  13. #43
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    It's those damn x-or's you gotta reach for.

    gg

  14. #44
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    It's not so bad with Rshift-left index...
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  15. #45
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >It's those damn x-or's you gotta reach for.
    But how often do you really need it?
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  2. delete and delete[]
    By Hunter2 in forum C++ Programming
    Replies: 13
    Last Post: 06-26-2003, 04:40 AM
  3. Pointers on pointers to pointers please...
    By Morgan in forum C Programming
    Replies: 2
    Last Post: 05-16-2003, 11:24 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM
  5. Pointers pointers pointers....
    By G'n'R in forum C Programming
    Replies: 11
    Last Post: 11-02-2001, 02:02 AM