[OCLUG-devel] sizeof () works differently on char's, int's, etc.

James Colannino james at colannino.org
Wed Jun 2 21:58:21 PDT 2004


Tim Thelin wrote:

> A way to get what you want, the number of elements of an array, could be 
> something more like:
> #define GetNumberOfElements( array )      ( sizeof( array ) / sizeof( 
> array[0] ) )
> That essentially gets the total bytes the array takes up, and divides it 
> by the size in bytes of a single element.  The resuilt is the number of 
> elements.


That is really cool :)  That definately solves my problem.  Thank you 
very much for your solution, and thank you John for explaining in such 
depth the way the sizeof() function works.

As long as nobody minds, I'll probably be creating quite a bit of noise 
on this mailing list as I go through my beginning C book :-P

James
-- 
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/

"There are no uninteresting things; only uninterested people." --G.K. 
Chesterton



More information about the OCLUG-devel mailing list