Hi, apologies since I feel this is a very basic question...

I need to feed a function that takes a few arguments, and I'm having trouble with one of the variables:

my_function(..., ..., const char* const*, ...)

I'm trying to initialize that variable like this:

const char* const myVariable[] = {
"",0
};

and then call the function like this:

my_function(..., ..., myVariable, ...)


This works, except if I later change the contents of myVariable. I guess it might be wrong to declare it as a const in the first place, but that's what the function demands. I'm a bit lost with this right now, so any help/guidance will be appreciated.

Thanks!

This works, except if I later change the contents of myVariable. I guess it might be wrong to declare it as a const in the first place, but that's what the function demands. I'm a bit lost with this right now, so any help/guidance will be appreciated.

How is it you change the contents of myVariable? You repoint to other literals?

const char* myVariable[] = 
{
   "",0
};

void my_function(const char* const* var)
{
}

int main()
{
   my_function(myVariable);
   return 0;
}

Thanks, I should have given a few more details...

I am not sure how the variable is changed. I am only writing this as a plugin against an API, and the 'function' I mentioned is actually a Class that I guess must have its own methods that I can't see. The variable is meant to store a list of labels, and I later change it through a user interface. I can see it changing just fine, but somehow those changes don't get saved. As in, a copy from that class object will have that variable initialized to the defaults again.

If it helps diagnosing it, someone told me to call that 'function' like this:

my_function(..., ..., &myVariable, ...)

But then I get an error when compiling:
"cannot convert `const char* const (*)[2]' to `const char* const*' for argument..."

And that's why I thought this might be a mistake in the way I'm declaring myVariable.

Thanks!

How is it you change the contents of myVariable? You repoint to other literals?

const char* myVariable[] = 
{
   "",0
};

void my_function(const char* const* var)
{
}

int main()
{
   my_function(myVariable);
   return 0;
}
This article has been dead for over six months. Start a new discussion instead.