R
Randall Parker
Have some dumb const questions even though I've been programming in C
and C++ for a long time. Given that the person whose code I took over
cast away const rather than figure out the answer I do not feel totally
dumb.
I want to pass in a pointer that moves thru a buffer where the buffer
is const but the pointer to it is not const. How the heck to do that?
Seems simple enough.
const int *someptr; // means the stuff pointed at is const
int * const someptr; // means the pointer itself is const.
const int **someptr; // I'm not sure what this means.
One can't have something like this:
void myotherfunc(const int **deeperptr)
{
// reads stuff out of **deeperptr
int abc = **deeperptr;
// increments *deeperptr
*deeperptr++;
// therfore the myfunc will see that xptr has changed.
}
void myfunc()
{
int xbuf[100];
int *xptr = xbuf;
myotherfunc(&xptr); // In C++ with MS VS 2003 this is illegal
because can't go from int ** to const **
}
So how to solve this problem? I want to
and C++ for a long time. Given that the person whose code I took over
cast away const rather than figure out the answer I do not feel totally
dumb.
I want to pass in a pointer that moves thru a buffer where the buffer
is const but the pointer to it is not const. How the heck to do that?
Seems simple enough.
const int *someptr; // means the stuff pointed at is const
int * const someptr; // means the pointer itself is const.
const int **someptr; // I'm not sure what this means.
One can't have something like this:
void myotherfunc(const int **deeperptr)
{
// reads stuff out of **deeperptr
int abc = **deeperptr;
// increments *deeperptr
*deeperptr++;
// therfore the myfunc will see that xptr has changed.
}
void myfunc()
{
int xbuf[100];
int *xptr = xbuf;
myotherfunc(&xptr); // In C++ with MS VS 2003 this is illegal
because can't go from int ** to const **
}
So how to solve this problem? I want to