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

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

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.

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

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

#include  #include  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:

Invalid arguments ' Candidates are: 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.

回答1:

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 ]".

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



回答2:

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

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

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.

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



回答3:

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

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

  • Symbol: __int64
  • Value: long long

Or you can upgrade your Eclipse CDT version



回答4:

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.

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

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



回答5:

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.



回答6:

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

static void sleep( u32 ms ); 

removed the issue.



回答7:

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

  • Clean your project (Project -> Clean)
  • Reindex files (Project -> C/C++ Index -> Rebuild)
  • Rebuild your project (Project -> Build All)


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!