Re: How can I get the size of this?



"David Webber" <dave@xxxxxxxxxxxxxxxxxxx> wrote in message
news:e6%23IwAxRFHA.3704@xxxxxxxxxxxxxxxxxxxx

In these matters "typedef" is often your friend!

LPCSTR is already typedef'd as "const char *",  so use it.

LPCSTR Data[]={"abc","bcd","cde","def","wot","shame"};

makes Data unambiguously an array of LPCSTRs, and

int nSize = sizeof  Data;

should get you the answer 24 (six times sizeof LPCSTR).

I can't see why the use of a typedef should make the slightest difference --- and on my system (VC++ 7.1) it doesn't. Indeed the OP's original code works fine. The following gives a value of 6 for szData.


int main()
{
   const char* Data[]={"abc","bcd","cde","def","wot","shame"};
   int szData = sizeof( Data ) / sizeof( Data[0] );
   return 0;
}


--
John Carson


.



Relevant Pages