相关疑难解决方法(0)

我是否施放了malloc的结果?

这个问题,有人建议意见,我应该不会投的结果malloc,即

int *sieve = malloc(sizeof(int) * length);
Run Code Online (Sandbox Code Playgroud)

而不是:

int *sieve = (int *) malloc(sizeof(int) * length);
Run Code Online (Sandbox Code Playgroud)

为什么会这样呢?

c malloc casting

2318
推荐指数
27
解决办法
22万
查看次数

1511
推荐指数
11
解决办法
72万
查看次数

如何使用extern在源文件之间共享变量?

我知道C中的全局变量有时会有extern关键字.什么是extern变量?宣言是什么样的?它的范围是什么?

这与跨源文件共享变量有关,但这是如何工作的?我在哪里用extern

c global-variables extern

942
推荐指数
13
解决办法
67万
查看次数

如何禁用几行代码的GCC警告

在Visual C++中,可以使用#pragma warning (disable: ...).我还发现在GCC中你可以覆盖每个文件的编译器标志.我怎样才能为"下一行"做这个,或者使用GCC围绕代码区域推送/弹出语义?

c gcc pragma compiler-warnings

200
推荐指数
8
解决办法
12万
查看次数

哪里C不是C++的子集?

我在很多书中读到C是C++的一个子集.

有些书说C是C++的一个子集,除了细节之外.

代码在C中编译但在C++中编译的情况有哪些?

c c++

111
推荐指数
9
解决办法
2万
查看次数

Visual Studio 2015:Extern"C"和"export"关键字

我正在努力将一个大型项目从VS2012迁移到VS2015(宝贝步骤,我知道),我遇到了一个问题,C头不再编译,错误保留c ++关键字 - 即使它们被包括在内与外部C.

这是一个简化的例子(2012年编译,但不是2015年)

main.cpp中

extern "C" {
    #include "cheader.h"
}

int main()
{
    printfFromC();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

cheader.h

#ifndef HEADER_H
#define HEADER_H

extern int export;
int printfFromC();

#endif
Run Code Online (Sandbox Code Playgroud)

ctest.c

#include "cheader.h"
#include <stdio.h>

int export = 0;

int printfFromC()
{
    export++;
    return printf("Hello from C (invocation %d) !\n", export);
}
Run Code Online (Sandbox Code Playgroud)

出现以下错误:

------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
  main.cpp
c:\[...]\cheader.h(4): warning C4091: 'extern ': ignored on left of 'int' when no variable is declared
c:\[...]\cheader.h(4): error …
Run Code Online (Sandbox Code Playgroud)

c c++ visual-studio

1
推荐指数
1
解决办法
294
查看次数