Thread: Knowing when function needs pass by reference.

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    2

    Knowing when function needs pass by reference.

    I would like to know how to tell when a function expects pass by reference.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by bsdunx View Post
    I would like to know how to tell when a function expects pass by reference.
    See if it takes a reference?

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You could look at the prototype for a function to see what arguments it expects, if that's what you mean. Or you could just try it one way, and if you get a compiler error/segmentation fault, try it the other way.

    And by pass-by-reference, you do mean via pointers, right?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Aug 2007
    Posts
    2
    I guess what I'm asking is how to tell just by looking at a prototype if you need to pass the address of a pointer or not.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Well, you could use a man page, online or otherwise. Stick the function into google, possibly along with "c function", and you'll most likely find information about it. There's a long list of websites like this here.

    Or you could always look at the header file itself. Look in /usr/include/stdio.h or C:\Dev-C++\Include\stdio.h or whatever, search for the function name, and you'll probably get it. Substitute whatever header file the function is in for stdio.h. If you don't know which header file it's in, search the whole directory. But you don't usually need to do this unless it's a very uncommon function or you don't have internet access.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  2. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM