Passing function as an argument.

This is a discussion on Passing function as an argument. within the C Programming forums, part of the General Programming Boards category; 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 ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    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, 01: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21