c

Effect of return type being static


What are the possible effect of returning a static type data. And when should we actually use it?

static ssize_t
my_read(int fd, char *ptr)
{
    //code from Stevens Unix Network programming. 
      if (something)
         return (-1)
      if (something else)
          return (0)


      return (1)
}

why static here?


Solution

  • The function is static, not the return type. This means that its name is only visible from within the current compilation unit, which is used as an encapsulation mechanism.

    The function can still be called from elsewhere through a function pointer, however.

    See also this discussion on the general static keyword for more context.