在GNU中是否与在Microsoft C运行时中弃用相同?
是否弃用,如果在GNU C中有这样的,在89/90或编译器之后由C的后续标准强制执行?
如果它是GNU C编译器,那么它何时提供如此安全的替代内存操作函数,就像在Microsoft C中memcpy_s弃用的memcpy那样?
如果它是89/90之后的C标准,那么它何时提供如此安全的替代内存操作功能,如同在Microsoft C中memcpy_s弃用的memcpy那样?
如果在GNU C运行时没有这样的弃用,是否有一个函数既不是那些内存操作(名称开头mem)也不是我所知道的那个bcopy,但我可以用来复制内存安全,因为它需要一个关于长度的参数目的地?
如果有/有,您能否尽可能多地列出?
什么是不安全的,哪个fopen更安全fopen_s?
如何以安全的方式使用fopen(如果可能的话)?
(我不想知道如何抑制警告 - 有足够的stackoverflow文章来回答这个问题)
编辑:问题被关闭为"基于意见"(即使只有一个答案,我没有看到太多的意见).我会尝试改写一下:如果有人能够展示微软(不赞成使用该功能)的文档如何/在哪里找到它,这将解释为什么它被弃用会更好.
这是我的第一篇文章,我不得不承认,我在编程方面很糟糕。我是班上努力工作的那个家伙,但似乎永远无法像其他同学一样掌握编程。因此,请保持友好,我将尝试在下面解释我的问题。
我有以下代码(删除了注释),但是当我运行它时,得到的警告类似于下面列出的警告。另外,当我运行程序时,允许输入第一个用户输入的值,但随后突然,它跳到程序的末尾,不允许我输入其他变量的值(例如,变量“ beta” )。我有输出的图片(http://i.stack.imgur.com/yc3jq.jpg),您可以看到我输入了alpha,但是程序运行到最后。有什么想法吗?
非常感谢您的帮助!-喷枪
- - - - - - - - - - - - - - -码 - - - - - - - -
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
float alpha, beta, h;
float slope_k (float, float, float, float);
float slope_q (float, float, float, float);
float slope_p (float, float, float, float);
int main (void)
{
float t0=0, tf, h, S0, I0, R0, k1, k2, k3, k4, q1, q2, q3, q4, p1, p2, p3, p4;
int N; …Run Code Online (Sandbox Code Playgroud) 在回答这个问题时,我在Ideone上编译了代码并得到了这个错误
implicit declaration of function ‘scanf_s’ [-Wimplicit-function-declaration]
Run Code Online (Sandbox Code Playgroud)
是不是stdio.h标题scanf_s?
我正在尝试使用 C11 函数strtok_s,该函数应该在 中定义<string.h>,但是当我尝试使用它时,clang 给了我一个链接错误。编译这个程序:
#include <string.h>
int main() {
char * buffer;
char * state;
rsize_t strmax = 0;
char * fpl = strtok_s(buffer, &strmax, "\n", &state);
}
Run Code Online (Sandbox Code Playgroud)
给我这个错误:
repro.c:7:15: warning: implicit declaration of function 'strtok_s' is invalid in
C99 [-Wimplicit-function-declaration]
char * fpl = strtok_s(buffer, &strmax, "\n", &state);
^
repro.c:7:9: warning: incompatible integer to pointer conversion initializing
'char *' with an expression of type 'int' [-Wint-conversion]
char * fpl = strtok_s(buffer, &strmax, "\n", &state); …Run Code Online (Sandbox Code Playgroud) 我试图从Beginning C 5th Ed这本书编译一个示例程序.作者:Ivor Horton.试图在OSX上编译它,我从gcc获得以下输出:
$ gcc program6_07.c
program6_07.c:18:59: warning: format specifies type 'int' but the argument has
type 'size_t' (aka 'unsigned long') [-Wformat]
"Terminate input by entering an empty line:\n", str_len);
^~~~~~~
program6_07.c:23:5: warning: implicit declaration of function 'gets_s' is
invalid in C99 [-Wimplicit-function-declaration]
gets_s(buf, buf_len); // Read a lin...
^
program6_07.c:24:9: warning: implicit declaration of function 'strnlen_s' is
invalid in C99 [-Wimplicit-function-declaration]
if(!strnlen_s(buf, buf_len)) // Empty lin...
^
program6_07.c:27:8: warning: implicit declaration of function 'strcat_s' is
invalid in …Run Code Online (Sandbox Code Playgroud) 我按照这本书,无法编译这个例子.有什么建议?
1 #define __STDC_WANT_LIB_EXT1__ 1
2 #include <string.h>
3 #include <stdio.h>
4
5
6 int main(void)
7 {
8 char source[] = "Here we go...";
9 char destination[50];
10
11 if(strcpy_s(destination, sizeof(destination), source))
12 printf("An error occurred copying the string.n");
13
14
15 return 0;
16 }
Run Code Online (Sandbox Code Playgroud)
错误:
/tmp/ccc5KZDZ.o: In function `main':
test.c:(.text+0x48): undefined reference to `strcpy_s'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud) 对于使用/不使用wcs/_w/_mbs前缀定义的函数的差异,我有点困惑.
例如:
fopen函数打开由filename指定的文件._wfopen是fopen的宽字符版本; _wfopen的参数是宽字符串.否则,_wfopen和fopen表现相同.
我只是怀疑是否有任何平台依赖于与添加"_w"前缀相关联的窗口.
wcscpy和_mbscpy分别是strcpy的宽字符和多字节字符版本.
如果"wcs"或"_mbs"的添加是依赖于平台的,则再次存在疑问.
编辑:
WideCharToMultiByte不是C运行时函数,它是Windows API,因此它取决于平台
它是非标准的,但在C11附件K中标准化.
我正在尝试用 c 语言编写一个简单的边缘检测程序。我使用的是 Red Hat Enterprise Linux Server 7.7 (Maipo) 和 gcc 版本 4.8.5。
这是代码的开头:
#include <stdio.h>
#define size 200
int _tmain(int argc, _TCHAR* argv[])
{
char filein[size] = "./image.bmp";
FILE *fin;
fopen_s(&fin, filein, "rb");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我最初对 _TCHAR* 有很多问题,所以最终我用 char 替换了它,我不知道这以后是否会成为问题,但至少它编译并消除了这些错误。现在我收到隐式声明警告。我尝试通过添加其他#include 来修复它。
我尝试用以下方法修复它:
#include <stdio.h>
#include <errno.h>
#include <string.h>
#define size 200
int main(int argc, char* argv[])
{
char filein[size] = "./image.bmp";
FILE *fin;
fopen_s(&fin, filein, "rb");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是,我仍然收到同样的警告,有人可以告诉我我做错了什么吗?
谢谢。
非常感谢,这有效!
#include <stdio.h>
#define size 200 …Run Code Online (Sandbox Code Playgroud) 我有一个C代码,其中有此行。
sprintf_s(var, outfile_ppm, local_filecounter++);
Run Code Online (Sandbox Code Playgroud)
在这里,var是char*类型,local_filecounter是int类型。
当我运行代码时,它发出以下警告:
警告:函数'sprintf_s'的隐式声明在C99中无效[-Wimplicit-function-declaration]
这是什么警告,我该如何消除它?