函式的返回值可以是指向結構體的指標例子://首先定義結構體struct lwip_socket { struct netconn *conn; struct netbuf *lastdata; u16_t lastoffset; u16_t rcvevent; u16_t sendevent; u16_t flags; int err;};//定義一個此結構體變數,注意宣告為staticstatic struct lwip_socket sockets[NUM_SOCKETS];//然後就可以用使用了static struct lwip_socket *get_socket(int s){ struct lwip_socket *sock; if ((s < 0) || (s > NUM_SOCKETS)) { LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): invalid\n", s)); set_errno(EBADF); return NULL; } sock = &sockets[s]; if (!sock->conn) { LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): not active\n", s)); set_errno(EBADF); return NULL; } return sock;}
函式的返回值可以是指向結構體的指標例子://首先定義結構體struct lwip_socket { struct netconn *conn; struct netbuf *lastdata; u16_t lastoffset; u16_t rcvevent; u16_t sendevent; u16_t flags; int err;};//定義一個此結構體變數,注意宣告為staticstatic struct lwip_socket sockets[NUM_SOCKETS];//然後就可以用使用了static struct lwip_socket *get_socket(int s){ struct lwip_socket *sock; if ((s < 0) || (s > NUM_SOCKETS)) { LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): invalid\n", s)); set_errno(EBADF); return NULL; } sock = &sockets[s]; if (!sock->conn) { LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): not active\n", s)); set_errno(EBADF); return NULL; } return sock;}