SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 06/03/2018, 02:58 PM   #1
wallen
Huge Clucker
 
wallen's Avatar
 
Join Date: Aug 2015
Location: Italia
Posts: 264
Reputation: 11
Default sizeof

How do you actually tell to someone what's a sizeof is ? in my words it's just returning a string on arrays, is that right?
__________________
Los Santos DM Battleground
wallen is offline   Reply With Quote
Old 06/03/2018, 04:18 PM   #2
Sew_Sumi
Godfather
 
Join Date: Jun 2008
Location: Azerbaijan
Posts: 6,181
Reputation: 515
Default Re: sizeof

It's working on how many cells are in the array.

Each character in a string is assigned a cell.

A string with the name Hello in it, would only need a string 5 long, and if it were str[5] and if we checked what str[2] was we'd end up with l (Or e... unsure on what it will return, but the 'address' is to the one character sitting in 2).


Sizeof isn't returning the string, it's simply returning the actual size of the array.
Sew_Sumi is offline   Reply With Quote
Old 06/03/2018, 04:24 PM   #3
wallen
Huge Clucker
 
wallen's Avatar
 
Join Date: Aug 2015
Location: Italia
Posts: 264
Reputation: 11
Default Re: sizeof

Thanks, appreciated
__________________
Los Santos DM Battleground
wallen is offline   Reply With Quote
Old 06/03/2018, 06:35 PM   #4
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Posts: 1,420
Reputation: 442
Default Re: sizeof

Also it's good to know that sizeof is a compiler directive, so it's not a function (unlike strlen for example). That implies you cannot use it on arrays with a size that's not known at compile-time (function arguments mostly).
That's why functions which write into arrays also need the size of the array passed seperately (like format).

It can be used on any variable as well, it doesn't neccessarily have to be an array (however there's almost no use-case except arrays, as all variables in PAWN are cells).
NaS is online now   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
sizeof Welaurs Scripting Help 2 08/06/2016 09:30 AM
Sizeof 2D array CalvinC Scripting Help 6 19/03/2016 07:47 PM
Sizeof? TheSy Scripting Help 5 04/06/2014 07:51 PM
sizeof array RedFusion Scripting Help 2 07/12/2012 03:21 PM
How to read the 2 sizeof ? UsaBoy91 Help Archive 1 13/10/2009 06:01 PM


All times are GMT. The time now is 04:24 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.