
Originally Posted by
mjs513
Been playing around with the Prop Shield IMU code and the only different warning I have been getting that I have not seen before is:
Code:
warning: argument to 'sizeof' in 'void* memset(void*, int, size_t)' call is the same
expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
memset(_ar, 0.0, sizeof(_ar));
Haven't gone back to give it a try in 1.37 though.
Note, you do not want to use 0.0 as an argument to memset, instead:
Code:
memset(_ar, 0, sizeof(_ar));
However, what it is likely warning you about is the variable _ar is likely a pointer, and not an array. Note, in C/C++, arrays are second class objects. If you pass an array to a function, the compiler converts the declaration within the function to be a pointer to the element, and it passes the pointer, instead of copying the entire array to a temporary on the stack.
So for example:
Code:
void clear (char foo[])
{
memset (foo, 0, sizeof (foo));
}
void bar (void)
{
char foo[100];
clear (foo);
// ...
}
is actually implemented as:
Code:
void clear (char *foo)
{
memset (foo, 0, sizeof (foo)); // sizeof char * is 4
}
void bar (void)
{
char foo[100];
clear (&foo[0]);
// only the first 4 bytes are cleared
// ...
}
What you should do is pass the length as a separate argument:
Code:
void clear (char *foo, size_t len)
{
memset (foo, 0, len);
}
void bar (void)
{
char foo[100];
clear (foo, sizeof (foo));
// ...
}