以下代码在64位和32位上的工作方式不同,这导致我无法移植我的代码。64位机器上的strtok
char * tmp = "How are you?";
printf("size of char * = %ld and size of strtok return val = %ld \n",sizeof(char *),sizeof(strtok(tmp," ")));
以下是输出:
32 bit:
size of char * = 4 and size of strtok return val = 4
64 bit:
size of char * = 8 and size of strtok return val = 4
的strtok的人页表示:
#include <string.h>
char *strtok(char *str, const char *delim);
RETURN VALUE
The strtok() and strtok_r() functions return a pointer to the next token, or NULL if there are no more tokens.
64位机器上的字符*被认为是8个字节作为打印。那么为什么strtok会在64位机器上返回一个4字节的字符指针?
感谢
您使用哪种编译器来获取这些结果? – Joel
你忘记了包含''吗?然后编译器可能会处于传统的情绪状态,并为其不知道的函数假设返回类型为“int”。 –
在'gcc-4.5.real(Ubuntu/Linaro 4.5.2-8ubuntu4)4.5.2'上确认。疯。 – sarnold