Hi,
On 26.01.2016 15:01, Neels Hofmeyr wrote:
my attention was directed at the gprs_shift_v_fixed() function:
int gprs_shift_v_fixed(uint8_t **data, size_t *data_len, size_t len, uint8_t **value)
It advances the *data pointer and returns a *value pointer. So it could technically be consting much more aggressively.
Yes it could if it was about plain information extraction. But these functions are used to get pointers to modifiable parts of the data for later patching.
So ideally there were two functions, one like the above, and another with the signature gprs_shift_v_fixed_const(const uint8_t **data, size_t *data_len, size_t len, const uint8_t **value)
Yes, C is not optimal for providing such a family of functions.
However, the compiler warnings confuse me.
[...]
check.c: In function ‘main’: check.c:10:14: warning: passing argument 1 of ‘func’ from incompatible pointer type func(&yy); ^ check.c:1:6: note: expected ‘const int **’ but argument is of type ‘int **’ void func(const int **yyy)
Changing yy to a pointer-to-const-int clears the warning:
const int *yy = y; func(&yy);
[...]
I just want to declare the underlying int data to be unchangeable by func(), not caring whether the caller passes a const int or a mutable int buffer.
Is the compiler merely nitpicking or am I getting something wrong fundamentally?
Perhaps http://stackoverflow.com/questions/28062095/pass-a-two-dimensional-array-to-... sheds some light on that.
Jacob