Dev C++ strtok_s throws [Warning] assignment makes pointer from integer without a cast
我有以下程序:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include <string.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { char *tp = NULL, *cp = NULL, *next_token = NULL; char TokenListe[] ="Hello,I Am,1"; tp = strtok_s(TokenListe,",", &next_token); printf(tp); return 0; } |
当我使用Visual Studio 2015对其进行编译时,它将在没有任何警告的情况下进行编译。
但是当我用Dev C 5.11编译它时,在第10行中收到以下警告:
[Warning] assignment makes pointer from integer without a cast
是否有解决此警告的解决方案?
由于C11,
但如果这样做,格式是这样的(C11 K.3.7.3.1):
1 2 3 4 5 6 7 | #define __STDC_WANT_LIB_EXT1__ 1 #include <string.h> char *strtok_s(char * restrict s1, rsize_t * restrict s1max, const char * restrict s2, char ** restrict ptr); |
任何其他格式都是非标准垃圾,因此不应使用,包括Microsoft strtok_s。
Dev C不再维护,因此仅包含非常老版本的gcc。它不支持C11,但据我所知,还没有较新版本的gcc库也支持C11边界检查接口。 Visual Studio是一个不合格的编译器,不能用于编译标准C。通常,我建议不要使用这两个编译器,而要更新到gcc的新版本(例如,带有Mingw的Codeblocks)。 >
摘要:
如果Dev C不具有非标准的strtok_s,则在C中将隐式声明它,并假定它返回整数。
注意:strtok_s在标准中,但是作为C11标准的我的免费草案副本,它是"可选扩展名"。
还应该启用其他警告,例如隐式声明函数的警告。
如果Dev C确实包含strtok_s的实现并与其链接,则声明自己可以运行。但是,更好的选择是找到正确的头文件或编译器标志,以将其声明(如果存在)。请查阅文档。
但是请注意,正如Michael Walz所说,C11标准中的strtok_s和Microsoft的strtok_s是不同的,并且没有相同的参数!我不知道Dev C实现的版本。
基于@ thomas-padron-mccarthy的回答,我可以通过在头文件中声明strtok_s函数来解决我的问题。
1 | extern char* strtok_s(char*, char*, char**); |