title: C: Implicit declaration of function
body: <p>I am working on an assignment in which we are developing our own RPC client. Upon compiling my server portion, I receive warnings for the following:</p>
  
  <pre><code>implicit declaration of function 'read'
  implicit declaration of function 'write'
  </code></pre>
  
  <p>I understand that I would typically receive this warning if I were to create a function following my main, ex:</p>
  
  <pre><code>int main() {
      doSomething();
  }
  
  void doSomething() {
      ...
  }
  </code></pre>
  
  <p>In the above case, it should complain about the function that I created "doSomething".</p>
  
  <p>Why then would my compiler complain that a system call was declared implicitly, when it appears in a function that was declared before the main? Below is the function in which the system call appears.</p>
  
  <pre><code>void Open(int connfd) {
  /*Get message size*/
  unsigned char temp[4] = { 0 };
  int n = read(connfd, temp, 4);
  if(n &lt; 0) {/*On error*/
      perror("Read error");
      exit(1);
  }/*End if*/
  unsigned int msgSize = temp[0] +
      (temp[1] * 256) + 
      (temp[2] * 256 * 2) + 
      (temp[3] * 256 * 3);
  printf("msgSize = %d\n", msgSize);
  
  /*Allocate memory for message*/
  char * msg = malloc(msgSize);
  if(msg == NULL) {
      perror("Allocation error");
      exit(1);
  }/*End if*/
  msg = memset(msg, 0, msgSize);
  
  /*Read entire message from client*/
  n = read(connfd, msg, msgSize);
  if(n &lt; 0) {/*On error*/
      perror("Read error");
      exit(1);
  }/*End if*/
  
  /*Extract pathname from message - NULL terminated*/
  char * pathname = malloc(strlen(msg) + 1);
  if(pathname == NULL) {
      perror("Allocation error");
      exit(1);
  }/*End if*/
  pathname = memset(pathname, 0, strlen(msg) + 1);
  pathname = memcpy(pathname, msg, strlen(msg));
  
  /*Extract flags from message*/
  int i;
  for(i = 0; i &lt; sizeof(int); i++) {
      temp[i] = msg[strlen(pathname) + 1 + i];
  }/*End for i*/
  unsigned int flags = temp[0] + 
      (temp[1] * 256) + 
      (temp[2] * 256 * 2) + 
      (temp[3] * 256 * 3);
  
  /*Extract mode from message*/
  for(i = 0; i &lt; sizeof(mode_t); i++) {
      temp[i] = msg[strlen(pathname) + 1 + sizeof(int) + 1 + i];
  }/*End for i*/
  mode_t mode = temp[0] + 
      (temp[1] * 256) + 
      (temp[2] * 256 * 2) + 
      (temp[3] * 256 * 3);
  
  free(msg);/*Free msg since it is no longer needed*/
  
  /*Open pathname*/
  umask(0);
  int fd = open(pathname, flags, mode);
  
  free(pathname);/*Free pathname since it is no longer needed*/
  
  /*Prepare response*/
  char * response = malloc(sizeof(int) * 2);
  if(response == NULL) {
      perror("Allocation error");
      exit(1);
  }/*End if*/
  response = memset(response, 0, sizeof(int) * 2);
  
  /*Build return message*/
  memcpy(&amp;response[0], &amp;fd, sizeof(fd));
  memcpy(&amp;response[4], &amp;errno, sizeof(fd));
  
  /*Can't guarante socket will accept all we try to write, cope*/
  int num, put;
  int left = sizeof(int) * 2; put = 0;
  while(left &gt; 0) {
      if((num = write(connfd, response + put, left)) &lt; 0) {
          perror("inet_wstream: write");
          exit(1);
      } else {
          left -= num;
          put += num;
      }/*End else*/
  }/*End while*/
  
  free(response);/*Free response since it is no longer needed*/
  
  return;
  }/*End Open*/
  </code></pre>