Thread: Passing function as an argument.

  1. #1
    Registered User
    Join Date
    Jan 2005

    Passing function as an argument.

    There are two functions in my code:
    void *memcpy(void *dest, const void *src, size_t n);
    in_addr_t inet_addr(const char *cp);
    I want to set IP address to an 4 element array in structure:
    memcpy(arp->src_pr_addr, inet_addr(""), 4);
    But then I get an error:
    arp_request.c:53: warning: passing arg 2 of `memcpy' makes pointer from integer without a cast
    But when I define another variable and pass its address everything works:
    long ip = inet_addr("");
    memcpy(arp->src_pr_addr, &ip, 4);
    How can I pass function directly to memcpy(); functions second argument? Do I need some casting? Thank you!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    You can't take the address of a return result - just use a temporary variable like you did in your last example.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Passing A Function Into A Constructor
    By fourplay in forum C++ Programming
    Replies: 6
    Last Post: 03-15-2009, 06:06 AM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. Passing my array to function
    By pooty tang in forum C Programming
    Replies: 8
    Last Post: 09-15-2004, 12:19 PM