ycycoco 发表于 2018-6-20 07:32:01

linux & windows porting-FlyingBear

  1. linux   int snprintf(char *restrict buf,>  windowsint _snprintf(
  2. 头文件都是string. h

  windows平台:函数:stricmp(char *str1, char *str2), strnicmp(char *str1, char *str2,>
  Linux平台: 函数:strcasecmp(char *str1, char *str2), strncasecmp(char *str1, char *str2,>  3. linux环境下是:vsnprintf
  VC6环境下是:_vsnprintf
  AString.cpplinux vasprintf()

[*]  static int vasprintf(char **strp, const char *fmt, va_list va)
[*]  {
[*]  const int required = vsnprintf(NULL, 0, fmt, va);
[*]  char *const buffer = (char *) malloc(required + 1);
[*]  const int ret = vsnprintf(buffer, required + 1, fmt, va);
[*]  *strp = buffer;
[*]  return ret;
[*]  }
  4. windows下winsock.h/winsock2.h
  linux下sys/socket.h    错误处理:errno.h
  5. write windows头文件
  include unistd.h
  6. socklen_t
  windows 头文件 #include<ws2tcpip.h>
  linux   下头文件
  1)#include <sys/socket.h>
  2)#include <unistd.h>
  7. _attribute__关键字主要是用来在函数或数据声明中设置其属性。给函数赋给属性的主要目的在于让编译器进行优化。函数声明中的__attribute__((noreturn)),就是告诉编译器这个函数不会返回给调用者,以便编译器在优化时去掉不必要的函数返回代码
  __attribute__((unused)) 告诉编译器这个函数可能不用,不需要报warning错误
  8. __typeof__
  decltype是根据变量推导获取出变量的类型
  9. GNU C的一大特色(却不被初学者所知)就是__attribute__机制。__attribute__可以设置函数属性(Function Attribute)、变量属性(Variable Attribute)和类型属性(Type Attribute)。
页: [1]
查看完整版本: linux & windows porting-FlyingBear