Il seguente codice funziona in modo diverso su 64 bit e su 32 bit, il che mi causa problemi nel trasferire il mio codice.strtok su macchine a 64 bit
char * tmp = "How are you?";
printf("size of char * = %ld and size of strtok return val = %ld \n",sizeof(char *),sizeof(strtok(tmp," ")));
Ecco l'output:
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
La pagina man di strtok dice:
#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.
Il char * su una macchina a 64 bit dovrebbe essere 8 byte come stampato. Allora perché strtok restituisce un puntatore char da 4 byte su una macchina a 64 bit ??
Grazie
Quale compilatore stai usando per ottenere questi risultati? – Joel
Hai dimenticato di includere ''? Quindi il compilatore potrebbe essere nell'umore tradizionale e assumere il tipo restituito 'int' per funzioni che non conosce. –
Confermato in 'gcc-4.5.real (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2'. Pazzo. – sarnold