帮我解释下这个头文件的定义

来源:百度知道 编辑:UC知道 时间:2024/09/24 21:48:26
#ifndef SFSOURCE_H
#define SFSOURCE_H

#ifdef __cplusplus
extern "C" {
#endif

int open_sf_source(const char *host, int port);
/* Returns: file descriptor for TinyOS 2.0 serial forwarder at host:port, or
-1 for failure
*/

int init_sf_source(int fd);
/* Effects: Checks that fd is following the TinyOS 2.0 serial forwarder
protocol. Use this if you obtain your file descriptor from some other
source than open_sf_source (e.g., you're a server)
Returns: 0 if it is, -1 otherwise
*/

void *read_sf_packet(int fd, int *len);
/* Effects: reads packet from serial forwarder on file descriptor fd
Returns: the packet read (in newly allocated memory), and *len is
set to the packet length
*/

int write_sf_packet(int fd, const void *packet, int len);
/* Effects: writes len byte packet to serial forwarder on file descriptor

最下面的#endif
是对应开头的:
#ifndef SFSOURCE_H
#define SFSOURCE_H
倒数第二个是对应这个的:
#ifdef __cplusplus
}
#endif

c++中使用c语言的函数时,需要把c语言的函数声明用extern "C"包括起来,告诉编译器这是c语言函数,编译器在生成c和c++的函数符号时方法不同,需要区分