const char * is incompat with type char *

I have a compiling example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main(int argc, char* argv[])
{

	SM_HANDLE seaMAXHandle;
	unsigned char data[2];
	int model, commType, baudrate, parity;


	// Open a COM 3	
	if (SM_Open(&seaMAXHandle, "COM3") < 0)
	{
		printf("Error opening COM 3.");
		return -1;
	}
	......

defined in the header, it's
 
	extern int __stdcall SM_Open(SM_HANDLE* handle, char* connection);


I use the exact same code in my project [inc headers] [a .dll project] and
Under the "COM3" I get error.

C++ argument of type is incompatible with parameter of type,
const char * is incompatible with type char *

what am I doing wrong so that it doesn't compile?
In all honestly I'd rather use something variable in it's place anyway but the only thing I've had not error [tried everything in my limited range] is a char * [pointer?] to a empty char [which I can't to be useful]

not wanting to bleat on about it but I'd really like to understand this correctly because often I just throw every thing, of the little I know, at it, sometimes it works,
It means that you cannot pass string literals (or other const-qualified values) as argument. You have to use a local string:

1
2
3
        char connection[] = "COM3";
        if (SM_Open(&seaMAXHandle, connection) < 0)
        ...

The docs (https://www.sealevelsoftware.com/documentation/seamax/win/group__group__seamax__all_gae40024bf17a375e88e3a0d1fd9547af5.html) for SeaMAX do not indicate any reason that is the case, or what modifications (if any) may be expected to be performed on the connection string, so I do not know whether a larger string than what I gave as example above is required or not.
Last edited on
Duthomhas, thank you, I missed trying that way but tried every other stupid way.
I understand how to deal with it now, but the question that still remains; how did the example handle it without issue.

No the messages are all simple, for seaLevel

c strings, I understand them, I have to use them all the time, I can mangle them at will but the amount of stupid problems I have with them. they symbolism in the error doesn't help.
You compile the example ok? But, a copy of it does not compile?
Oh, that was an example? Heh, I have no idea how it compiled — not without some very carefully placed flags telling the compiler to ignore the distinction.
Topic archived. No new replies allowed.