Alan,
At 08:38 AM 8/26/99 -0500, you wrote:
>dbErrType DBGetCellPtr_RO(DBOpenDBInfoType* gdb, char* colName, ULong
>row, ULong* dataSize, const void** dataP);
>// the const declaration makes this line illegal:
>**dataP = 5; // can't assign data to const
You have fallen into the dreaded const-declaration trap.
"const void ** dataP" means that the value pointed to by dataP can not be
changed. Please consider this carefully. It does not mean that the stuff
the pointer that dataP points to can't be changed, but that the value of
dataP can't be changed. Perhaps an example will help (we'll deal with
char's instead of voids for clarity):
char* data = "A string";
const char** dataP = &data;
// Legal stuff:
**dataP = '\0'; // data now equals ""
*data = 'T'; // data is "A string" again.
data = "Another String"; // this is fine - the value of data (ie what
it points to) can change.
// Let's break the law:
*dataP = "First string"; // This is *illegal* - the value of (*dataP)
is const!
This is almost certainly not what you want. So let's figure out what you
do want:
First, we want a pointer to constant data (we'll go back to voids here):
const void*
We can also write this as
void const*
While less usual and a bit awkward, this is actually easier to figure out -
reading right to left we get a pointer to constant void.
So, if we want a pointer to this, we want:
void const **
Or a pointer to a pointer to constant void.
Reworking your declaration, we'd get
void * const *
Which is a pointer to a constant pointer to void.
I hope this is clear. This is one of the more difficult nuances of 'C'
declarations, and I myself have had to rewrite this several times to make
sure I got it right. In fact, when I ran the above sample through VC6, it
choked
const char** dataP = &data;
Metrowerks seemed to handle it better.
Anyhow, that's my understanding. I'm sure someone will come along and
debate it; but if this works I'll take those beers!
Regards,
Greg
Greg Winton
Bachmann Software and Services, LLC
mailto:[EMAIL PROTECTED]
http://www.bachmannsoftware.com
Software Development for Handheld & Mobile Computing, Windows and the Internet
Home of Bachmann Print Manager, the only graphical printing solution for
the Palm Computing Platform