Re: How can I get the size of this?
- From: "David Webber" <dave@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 22 Apr 2005 08:51:51 +0100
"Carl" <carl8421@xxxxxxx> wrote in message
news:uA09JQwRFHA.3336@xxxxxxxxxxxxxxxxxxxxxxx
> I am now having a problem at using sizeof() function
Don't think of it as a function - it isn't one. It's an operator.
I perefer to use it without brackets just to remind myself that it
is an operator.
Operating on something declared as a pointer returns the size of
the pointer.
Operating on something declared as an array returns the size of the
array (and not the size of the pointer you would have by using the
array name as a pointer).
So you have to be very clear which you have.
So for example in
> int szData = sizeof( (char*) Data )/ sizeof( Data[0] );
you are explicitly finding the ratio of the size of a char *
(unambiguously, because you have explicitly cast it) and dividing by
the size of a char *.
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).
Dave
--
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm
.
- Follow-Ups:
- Re: How can I get the size of this?
- From: John Carson
- Re: How can I get the size of this?
- From: Victor Bazarov
- Re: How can I get the size of this?
- References:
- How can I get the size of this?
- From: Carl
- How can I get the size of this?
- Prev by Date: Re: 3rd party library in VC++/MFC
- Next by Date: Re: Bulk insert to sql database
- Previous by thread: How can I get the size of this?
- Next by thread: Re: How can I get the size of this?
- Index(es):
Relevant Pages
|