Thread: Using address of a parameter of a function

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    98

    Using address of a parameter of a function

    I inherit this piece of code:
    Code:
     
    struct LINK *link_id_search(int link_id)
    {
      struct LINK *link;
      link = (LINK *) splaySearch(daemon_body.links, &link_id);
      return link;
    }
    It passes the address of a primitive-data-type parameter (&link_id) to another function. I have never seen this. Is this legal? Does it have a defined behavior?
    The type of the 2nd parameter of splaySearch() is void *.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It is perfectly legal and valid.

    However, if you in your search function STORE the pointer "permanently" it would be undefined behaviour as the local variable would disappear. I doubt that the search code actually does store it, tho'.

    --
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Replies: 13
    Last Post: 08-24-2006, 12:22 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM