I am trying to pass a character pointer array as an input from C test driver to C++ function (available in C wrapper)
char* LowerList[10];
LowerList[0]="abc";
LowerList[1]="def";
LowerList[2]="hij";
When available on the C++ side the values displayed for the the element is displayed as
char* LowerList[0]="abc";
LowerList[1]="def";
LowerList[2]="hij";
LowerList[3]=ƒì¶S<\$ UV<35?Ä@
LowerList[34]=ƒ<bad pointer>
I need to get the size of the array passed on to the C++ size which I could have got using
while (LowerList[count]) but unable to do so because of the junk value.
Please let me know if any way I can find the correct size of the char* LowerList[] by initialising ,memory allocation or converting it to vector.
Corrected the above code for typo error
Here are my comments on some of the suggestions given to me so far:
1) Pass the size of the array as a parameter as well- A limitation for my scenario .2) Conversion to the vector need the size to be available 3) Sentinel value at which position I need to add . As stated earlier I am trying to handle a scenario where the user pass the value as 3 which leads to the failure.I don’t have any control on restricting the way C user my C++ wrapper with his C test driver.
The pointers
LowerList[3]throughLowerList[9]are all uninitialized, if I’m not mistaken. You could always just use NULL as a sentinel value, and either assign it explicitly or do something like this:This should initialize the remaining pointers in the array to NULL.
In response to your second comment:
Or something like that.
http://en.wikipedia.org/wiki/C_preprocessor#User-defined_compilation_errors_and_warnings