Error with passing by reference

This is a discussion on Error with passing by reference within the C Programming forums, part of the General Programming Boards category; I have these two prototypes Code: /home/spyder/sh0ck/list.h:29: error: parse error before '&' token /home/spyder/sh0ck/list.h:30: error: parse error before '&' token ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    3

    Error with passing by reference

    I have these two prototypes
    Code:
    /home/spyder/sh0ck/list.h:29: error: parse error before '&' token
    /home/spyder/sh0ck/list.h:30: error: parse error before '&' token
    The error is in these two prototypes
    Code:
    char *readSock( int fd, int &len );
    int handle( int sockfd[20], int &index, fd_set *set, int fdmax );

  2. #2
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    references are C++ only.

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    You can simulate passing by reference in C by passing a pointer.
    Its not as easy as the C++ way but it can be done.
    Code:
    #include <stdio.h>
    
    void fun (int *);
    
    int main (void)
    {
      int x=4;
      printf("Before %d\t",x);
      fun(&x);
      printf("After %d\n",x);
      return 0;
    }
    
    void fun (int *a)
    {
      (*a) = (*a) * 4;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 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
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM

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