Eclipse 给了我无效参数 ' Candidates are: void * memset(void *, int, ?) ' 虽然我知道参数很好

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13021594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 21:23:02  来源:igfitidea点击:

Eclipse giving me Invalid arguments ' Candidates are: void * memset(void *, int, ?) ' though I know the args are good

eclipsememset

提问by djc6535

I am getting an invalid arguments error in eclipse, though I am confident my arguments are good. The suggested arguments contains a '?' which I think may indicate the problem, though I do not know how to fix it.

我在 Eclipse 中遇到无效参数错误,但我确信我的参数是好的。建议的参数包含一个“?” 我认为这可能表明问题所在,尽管我不知道如何解决它。

I have done my best to copy the example I saw here:
http://www.cplusplus.com/reference/clibrary/cstring/memset/

我已尽力复制我在这里看到的示例:http:
//www.cplusplus.com/reference/clibrary/cstring/memset/

In order to be certain that I am getting the args right.

为了确定我的参数是正确的。

#include <stdio.h>
#include <string.h>
void foo()
{
    char str[] = "why oh why does my IDE give me errors when I know my args are good?";
    memset(str, '-', 4);
    puts(str);
}

Eclipse gives me the following error on the memset line:

Eclipse 在 memset 行上给了我以下错误:

Invalid arguments ' Candidates are: void * memset(void *, int, ?) '

无效参数 ' 候选人是: void * memset(void *, int, ?) '

What could be causing this? And what is up with that '?' as the 3rd arg?

什么可能导致这种情况?那“?”是怎么回事?作为第三个参数?

Thanks in advance!

提前致谢!

PS: Just noticed I am getting similar errors when I try to use operations like malloc, calloc, etc.

PS:刚刚注意到当我尝试使用 malloc、calloc 等操作时遇到了类似的错误。

回答by Catskul

In Eclipse:

在日食中:

  • right click the project
  • click properties
  • Expand "C/C++ general"the item in the left hand tree view by clicking the arrow, (just clicking the item itself does not expand the suboptions)
  • From the suboptions select "Preprocessor Include Paths, Macros etc."
  • Click the "Providers"tab
  • Check the box next to "CDT GCC Built-in Compiler Settings [ Shared ]".
  • 右键单击项目
  • 单击属性
  • 通过单击箭头展开左侧树视图中的C/C++ 常规项目,(仅单击项目本身不会展开子选项)
  • 从子选项中选择预处理器包括路径、宏等”。
  • 单击提供商选项卡
  • 选中CDT GCC 内置编译器设置 [共享]旁边的框。

Edit:

编辑:

The reason this works is that there are a bunch of default includes and defines that the compiler silently adds behind the scene when you compile. These instructions get eclipse to grab these otherwise silent preprocessor directives so that it's own indexer is using the same settings

这样做的原因是有一堆默认包含并定义编译器在编译时在幕后默默添加。这些指令让 eclipse 获取这些原本无声的预处理器指令,以便它自己的索引器使用相同的设置

回答by Ramesh-X

The following method resolves the same problem that I was having. (on eclipse 4.2)

以下方法解决了我遇到的相同问题。(在日食 4.2 上)

  • Clean your project (Project-> Clean)
  • Reindex files (Project-> C/C++ Index-> Rebuild)
  • Rebuild your project (Project-> Build All)
  • 清理你的项目 ( Project-> Clean)
  • 重新索引文件 ( Project-> C/C++ Index-> Rebuild)
  • 重建您的项目 ( Project-> Build All)

回答by Jonathan Leffler

I think it is something to do with your Eclipse setup, somehow.

我认为这与您的 Eclipse 设置有关,不知何故。

Taken standalone, that fragment compiles under GCC (G++) 4.7.1 on Mac OS X 10.7.5 with the command line:

单独使用,该片段在 Mac OS X 10.7.5 上的 GCC (G++) 4.7.1 下使用命令行编译:

g++ -O3 -g -Wall -Wextra -c ms.cpp

The only surprising thing about the third argument to memset()is that it is of type size_t, but the headers are supposed to declare that, so it should not be an issue.

第三个参数 to 唯一令人惊讶的memset()是它是 type size_t,但是标题应该声明它,所以它不应该是一个问题。

If you're using malloc()et al, you will be including <stdlib.h>, of course. There is also room to argue that you should be using <cstdio>, <cstring>and <cstdlib>, but that shouldn't stop the code you presented from compiling without error.

如果您使用的是malloc()et al,<stdlib.h>当然会包括。也有争论您应该使用<cstdio>, <cstring>and 的空间<cstdlib>,但这不应阻止您提供的代码无误地编译。

回答by JACH

If you're working with Visual Studio, size_t is defined as

如果您使用的是 Visual Studio,则 size_t 定义为

typedef unsigned __int64    size_t;

In previous versions of the Eclipse CDT, __int64 was not defined. You can fix that issue by adding into C/C++ General -> Paths and Symbols -> Symbols

在早期版本的 Eclipse CDT 中,未定义 __int64。您可以通过添加到 C/C++ General -> Paths and Symbols -> Symbols 来解决该问题

  • Symbol: __int64
  • Value: long long
  • 符号:__int64
  • 值:长长

Or you can upgrade your Eclipse CDT version

或者您可以升级您的 Eclipse CDT 版本

回答by Raam Kumar

I've been using a 3rd party C++ library for BeagleBone development and I tried every possible way to include it (as preprocessor includes, source folder, assember includes, library includes, C++ compiler includes, C compiler includes etc). Refreshen, reindex, clean and built for every change I attempted. I even deleted the project and copied only the .cpp and .h files over to a new project.

我一直在使用 3rd 方 C++ 库进行 BeagleBone 开发,我尝试了所有可能的方法来包含它(如预处理器包含、源文件夹、汇编包含、库包含、C++ 编译器包含、C 编译器包含等)。为我尝试的每次更改刷新、重新索引、清理和构建。我什至删除了该项目,仅将 .cpp 和 .h 文件复制到新项目中。

I finally found the problem in my setup and rectified it as follows.

我终于在我的设置中找到了问题,并按如下方式进行了纠正。

Right-click the project > Properties > C/C++ Build > Tool-chain editor > Current Builder:> Select CDT Internal Builder

右键单击项目 > 属性 > C/C++ Build > Tool-chain editor > Current Builder:> 选择CDT Internal Builder

I'm using g++, for your information.

我正在使用 g++,供您参考。

回答by Serge Roussak

I had a similar issue with the Eclipse CDT. But in my case the thing was that I had put the using namespace std;statement in a several headers. And in some combination of conditions, when I included all of this headers the Eclipse had such the behavior.

我有一个与 Eclipse CDT 类似的问题。但就我而言,问题是我将using namespace std;语句放在了几个标题中。在某些情况下,当我包含所有这些标题时,Eclipse 会出现这种行为。

回答by wilsan

I had a similar issue when compiling someone's code, and the problem was the code style. They defined some methods in this way:

我在编译某人的代码时遇到了类似的问题,问题出在代码样式上。他们以这种方式定义了一些方法:

// ... Inside a class

static void
sleep( u32 ms );

I guess this is GNU style. Just changing the declaration to

我想这是 GNU 风格。只需将声明更改为

static void sleep( u32 ms );

removed the issue.

删除了这个问题。