Raised This Month: $ Target: $400
 0% 

Sizeof and charsmax?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-20-2010 , 00:39   Re: Sizeof and charsmax?
Reply With Quote #8

sizeof() returns the size of an array. (# of cells)
charsmax() is a macro for sizeof()-1.

string.inc
PHP Code:
#define charsmax(%1) (sizeof(%1)-1) 
As fysiks said, you will almost always use charsmax() when dealing with strings since 1 array cell must be reserved for a null character. In both of your code blocks above it is correct to use charsmax().

When working with arrays and you need to access every cell in the array in a loop or w\e, you would use sizeof().
PHP Code:
new iArray10 ]; //elements are accessed using index 0 through 9

//this loop will reach every element in the array from 0 to 9.

for ( new sizeofiArray ) ; i++ )
//equal to 
for ( new 10 i++ )

//if you used charsmax(), cell index 9 would never be reached.

for ( new charsmaxiArray ) ; i++ )
//equal to 
for ( new i++ ) 
__________________

Last edited by Bugsy; 08-20-2010 at 00:43.
Bugsy is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode