c - Dev C++ strtok_s 抛出 [警告] 赋值使指针来自整数而不进行强制转换

标签 c c11 tr24731

我有以下程序:

#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 起,strtok_s 现在是标准 C,是可选“边界检查接口(interface)”(附录 K)的一部分。编译器不需要支持它。

但如果他们这样做,格式是这样的(C11 K.3.7.3.1):

#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 边界检查接口(interface)。 Visual Studio 是一个非一致性编译器,不能用于编译标准 C。一般来说,我建议不要使用这些编译器,而是更新到新版本的 gcc(例如 Codeblocks with Mingw)。

摘要:strtok_s 不能以合理的方式使用。请改用 strtok。只需确保涉及的所有缓冲区足够大并且不会溢出。对于多线程程序,根本不要使用 strtok

关于c - Dev C++ strtok_s 抛出 [警告] 赋值使指针来自整数而不进行强制转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49065129/

相关文章:

c - 没有任何参数和返回值的 C 函数是否需要堆栈才能执行?

c - isspace() 是否接受 getchar() 值?

c - 错误 : use of undeclared identifier 'errno_t'

c - “shall be a pointer to the initial element of an array of character type” 在 C99 7.19/C11 7.21 中是什么意思?

c - 当 "pointer to an object type"与 "pointer to a void"比较相等时,如何理解转换规则?

c - 符合要求的实现是否需要支持 C11 中的附件 K?

c - 使用字符串的简单程序

c++ - 是 char 空终止符是否包含在长度计数中

c - X 工具包 : heap is growing when recreating widgets

c - gcc,枚举未按预期打包