Open ljden opened 1 year ago
I've just been hit with this as well, and it's definately something that cmock does. A simple example to replicate is attached and written below:
foo.zip contains foo.h:
#ifndef FOO_H
#define FOO_H
int foo(int bar[4]);
#endif
On a command line run:
ruby <path to>\cmock.rb foo.h
And you will get this generated in "Mockfoo.c":
int foo(int* bar)
{
[...]
}
Which then causes a compiler warning with gcc.
It seems to be done in CMock/lib/cmock_header_parser.rb, line 479-480, but I assume there would be many knock on effects if you changed it away from converting arrays to pointers. I haven't tried, I don't know enough ruby.:
# magically turn brackets into asterisks, also match for parentheses that come from macros
arg_list.gsub!(/(\w+)(?:\s*\[[^\[\]]*\])+/, '*\1')
This already seems to be reported in #69, but that specifically mentions multidemensional arrays but I assume it happens for any arrays.
Hi. I'm going to admit something here. We took a shortcut WAaaaaaaaaay back when we wrote CMock. We said "internally, arrays and pointers are the same thing... and internally multidimensional arrays are just single dimension arrays accessed differently." It was a hack and it was meant to get to version 1 and then get fixed.
Then it didn't get fixed.
For a long time.
And I feel embarrassed and I deeply apologize for how long we've let that slide. This is an issue that should have been fixed a long long time ago.
It's not a hard problem to solve. It IS a nuanced problem. That means that I know that when I start working on it, it's going to require a time investment to do it right. And it's worth doing it right. So far that's kept me from tackling it in my slivers of free time.
I intend to change that pattern soon. Hopefully I'm not adding words here that I will further regret. ;)
Note that in this particular case, you can try -Wno-array-parameter
in GCC to suppress the warning (and error with -Werror
) to work around that limitation, which we did in IDF to enable mocking of that component. However, it does not seem to work with re-declarations of two-dimensional arrays, e.g. esp_err_t esp_efuse_write_keys(const esp_efuse_purpose_t* purposes, uint8_t* keys, unsigned number_of_keys)
(generated) vs esp_err_t esp_efuse_write_keys(const esp_efuse_purpose_t purposes[], uint8_t keys[][32], unsigned number_of_keys);
(original).
I am trying to mock an esp-idf component with CMock and the build is failing due to a mismatch in function definition from a
const uint8_t[6]
in the original header to aconst uint8_t[6]
in the mock header. Have I missed something or does CMock not handle this case correctly?I'm not 100% sure if this is an issue on the CMock or esp-idf side. If you think it is not CMock, let me know and I'll open a ticket on esp-idf