A1A2A3A4
A1A2A3A4

Reputation: 453

Compiler claims pointer is const when it is not used

My compiler gives this warning:

inlinedata.h:9:6: note: expected ‘char *’ but argument is of type ‘const char *’

int  inline_data_receive(char *data,int length);

I don't understand why it claims 'data' is a const pointer when it is not written as a const char*.

Upvotes: 1

Views: 303

Answers (2)

ooga
ooga

Reputation: 15501

It's saying that the argument (the data that you are passing in) is const. It might be a string literal, for example. So instead of doing this:

ret = inline_data_receive("hello", len);

do this

char str[] = "hello";
ret = inline_data_receive(str, len);

You need to do it this way since the function is not guaranteeing that it won't modify the input string.

Upvotes: 5

JaredPar
JaredPar

Reputation: 754745

The compiler is complaining that you are passing a const char* value to a value that is labeled as char*. Essentially the following

const char* c = ...;
inline_data_receive(c, strlen(c));

The compiler is complaining that c is const char* but needs to be char* to line up with the argument data

Upvotes: 3

Related Questions