Thread: Passing function as an argument.

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    30

    Passing function as an argument.

    Hi!
    There are two functions in my code:
    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:
    Code:
    memcpy(arp->src_pr_addr, inet_addr("127.0.0.1"), 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:
    Code:
    long ip = inet_addr("127.0.0.1");
    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
    Location
    The edge of the known universe
    Posts
    39,659
    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