Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

eclipse

memset

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

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.

like image 872
djc6535 Avatar asked Oct 22 '12 23:10

djc6535


3 Answers

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

like image 63
Catskul Avatar answered Nov 17 '22 15:11

Catskul


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)
like image 12
Ramesh-X Avatar answered Nov 17 '22 14:11

Ramesh-X


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

like image 1
Jonathan Leffler Avatar answered Nov 17 '22 13:11

Jonathan Leffler