Re: pointers...

Discussion in 'C Programming' started by Simon Biber, Jun 25, 2003.

  1. Simon Biber

    Simon Biber Guest

    "geo" <geometrikal@hhoottmmaaiill> wrote:
    > and then i had a function which used this structure. What
    > is the best programming practice:
    >
    > void function(struct random_struct * r) {
    > .......
    > }
    >
    > function(&random);
    >
    > or:
    >
    > void function(struct random_struct r) {
    > .......
    > }
    >
    > function(random);


    There is no 'best programming practice'. They do very
    different things. Use the former when you want to modify
    the existing copy of the struct in place, and use the
    latter when you want to have a fresh copy that you can
    modify, without changing the original.

    If you don't want to modify it at all, the function
    should take a pointer to const struct random_struct.

    --
    Simon.
    --
    comp.lang.c.moderated - moderation address:
    Simon Biber, Jun 25, 2003
    #1
    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. Phil
    Replies:
    1
    Views:
    643
    llewelly
    Sep 16, 2003
  2. muser
    Replies:
    3
    Views:
    759
    Ron Natalie
    Sep 18, 2003
  3. A
    Replies:
    3
    Views:
    450
    Alan Kelon
    Oct 29, 2003
  4. Xamalek
    Replies:
    7
    Views:
    685
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    667
Loading...

Share This Page