Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » CDT code analysis C++ error markers for sizeof and va_list(CDT code analysis C++ error markers)
CDT code analysis C++ error markers for sizeof and va_list [message #1795342] Thu, 20 September 2018 15:03 Go to next message
Mark Cooper is currently offline Mark CooperFriend
Messages: 1
Registered: September 2018
Junior Member
I am seeing a couple error markers being displayed only for C++ files by Eclipse CDT that I am not sure are desireable. Here are some examples:

1) When sizeof passed as an argument to another function, something that is done often, I am seeing CDT complain about the type returned. Here's an example:

memset(handle,0,sizeof(handle));

CDT complains because the prototype we have defined is
extern void *memset (void *__s, int __c, size_t __n) __THROW;

CDT error:
Invalid arguments 'Candidates are: void * memset(void *, int, unsigned long int)'

Size_t is defined as follows: typedef unsigned long size_t;

I assume I see the error because sizeof in C++ returns a std::size_t. Of course I have a way around this (can cast the result of sizeof()), but wonder if this is the intended behavior.


2) va_list, va_start and va_end could not be resolved. Here's one error:

CDT error:
Type 'va_list' could not be resolved

Anything defined with va_list will consequently give an error:
my code:
vsnprintf(buffer,255,fmt,arg);

CDT error:
Invalid arguments 'Candidates are: int vsnprintf(char *, unsigned long int, const char *, ?)'

Thanks for any input,

Mark




Re: CDT code analysis C++ error markers for sizeof and va_list [message #1795363 is a reply to message #1795342] Fri, 21 September 2018 01:15 Go to previous message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
These don't seem to have much to do with CDT.

1) I defined a function MEMSET similar to yours.
What is the declaration of handle used in your call: memset(handle,0,sizeof(handle)) ?
if it isn't a pointer then the call is incorrect.
The following works:
    #include <cstddef>    // for size_t

    void * MEMSET(void *__s, int __c, size_t __n);
    int handle;

    MEMSET(&handle,0,sizeof(handle));
	
    int HAND[5];
    MEMSET(HAND,0,sizeof(HAND));


The above also work when I declare:
typedef unsigned long int SIZE_T;
void * MEMSET(void *__s, int __c, SIZE_T __n);

2) va_list is defined in <cstdarg>
Did you include it?
The following worked for me:
#include <cstdarg> // for va_list
#include <cstdio>  // for vsnprintf

 char buff[256];
 char * fmt;
 va_list arg;
 vsnprintf(buff, sizeof(buff)-1, fmt, arg);




[Updated on: Fri, 21 September 2018 03:28]

Report message to a moderator

Previous Topic:Real time refresh of "expressions" ( Global ) - Error: Target not available.
Next Topic:Changing Include path
Goto Forum:
  


Current Time: Fri Apr 26 13:47:28 GMT 2024

Powered by FUDForum. Page generated in 0.03542 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top