I need to get the size of the array passed on to the C++ size which I could have got using while (LowerList[count])loop but unable to do so because of the junk value on the 4th position. 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.
I am able to get the size of the array if its specified as
Also Is there a way I can initialise char* LowerList[10] in my C test driver without specifying the size as 10 as the code in the C wrapper accessing C++ function or I can do something to this array on the C++ side(e.g. realloc,vector etc) to get a temination value and get its size ingnoring the junk values
Updated on 7/15:Adding a NULL(sentinel value) or passing the size of the array is out of scope of my scenario.
I am trying a handle a case where user has done the declaration on the C side as
char* LowerList[3] = { "abc", "def", "hij" }; and I have to handle this on C++ side.
If someone can suggest this handling on the C++ side then its of great help for me as the C area is a grey one for me and it upto the user to give any inputs as long as C test driver compilation is a success.
1) Pass the size as an additional parameter to the function.
2) Add a "sentinel" value the end of the array -- a NULL pointer. So char* LowerList[] = { "abc", "def", "hij", 0 }; then loop until you get to a NULL.
3) Templates:
1 2 3 4 5
template< typename T, size_t N >
void do_it( T (&array)[ N ] ) {
for( size_t i = 0; i < N; ++i )
std::cout << array[ i ] << std::endl;
}
Yes, Active Template Library. Why does it seem obsolete to you? The newest OS additions are COM-based, like Credential Providers. COM rules, simply put.
COM is very actively used in all versions of windows operating system. There are APIs only available trough COM interface (for example creating/resolving a shortcut)