我在第5行的错误中遇到了以下代码的问题:
错误:无效转换
void*为char*
我正在使用g ++和codeblocks,我试图将此文件编译为cpp文件.有关系吗?
#include <openssl/crypto.h>
int main()
{
char *foo = malloc(1);
if (!foo) {
printf("malloc()");
exit(1);
}
OPENSSL_cleanse(foo, 1);
printf("cleaned one byte\n");
OPENSSL_cleanse(foo, 0);
printf("cleaned zero bytes\n");
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用strndup函数,但是我得到了错误
错误:函数'strndup'的隐式声明[-Werror = implicit-function-declaration]
我四处搜索,发现它不是标准函数,因此我必须使用不同的标志进行编译.但是,我通过以下编译收到同样的问题:
-std=gnu11
-Wall
-Wextra
-Werror
-Wmissing-declarations
-Wmissing-prototypes
-Werror-implicit-function-declaration
-Wreturn-type
-Wparentheses
-Wunused
-Wold-style-definition
-Wundef
-Wshadow
-Wstrict-prototypes
-Wswitch-default
-Wunreachable-code
-D_GNU_SOURCE
Run Code Online (Sandbox Code Playgroud)
我正在做一个任务,因此我必须使用所有这些,但我发现我必须使用'-D_GNU_SOURCE'进行编译才能使错误消失,但事实并非如此.
编辑:
我也包括这些:
#define __STDC_WANT_LIB_EXT2__ 1
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
Run Code Online (Sandbox Code Playgroud)
非常感谢帮助解决这个问题.