Raised This Month: $130 Target: $400
 32% 

Get sizeof array in a macro


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shauli
Junior Member
Join Date: Jun 2018
Old 06-12-2018 , 14:24   Get sizeof array in a macro
Reply With Quote #1

Hello all.

I've made the following code, which is in my include:
PHP Code:
#define calculateArray[%1,%2] _calculateArray(%1,%2,sizeof %1)

stock _calculateArray(array[], numsize)
{
    
//some unimportant stuff here

Since I can't access directly to the sizeof function inside my include file (and I don't want to manually pass the parameter), I've created a macro that will automatically do that for me.

My problem is that it works fine when I use it like this:
PHP Code:
new array[6];
calculateArray(array, 3); 
But I get an error when I try to use it like this:

PHP Code:
new array[4][6];
calculateArray(array[0], 3); 
Code:
WARNING [273]: expression has no effect
ERROR [273]: expected token: "]", but found "-integer value-"
ERROR [273]: expected token: ";", but found "]"
ERROR [273]: invalid expression, assumed zero
I think that the macro passed "sizeof array[0]" thus making an error. Some workaround for this?
Thanks in advance.

Last edited by shauli; 06-12-2018 at 14:26.
shauli is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-12-2018 , 15:50   Re: Get sizeof array in a macro
Reply With Quote #2

you can check sizeof array into _calculateArray stock, why you need to pass it?

also what you need to do with new array[4][6]; exactly?
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar,get_pcvar_num(pCvar) ? 1); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
shauli
Junior Member
Join Date: Jun 2018
Old 06-13-2018 , 05:24   Re: Get sizeof array in a macro
Reply With Quote #3

Quote:
Originally Posted by ^SmileY View Post
you can check sizeof array into _calculateArray stock, why you need to pass it?

also what you need to do with new array[4][6]; exactly?
This stock is inside my include file which I use in many different plugins that are not related to one another. Just a custom-made include.

When I try to use sizeof inside the stock (in the include file) I get this error:
Code:
WARNING [25]: indeterminate array size in "sizeof" expression (symbol "")
About the "array[4][6]" that is just an example. Here's another example that will make more sense:
PHP Code:
new values[MAX_PLAYERS+1][4];
//code......

public someStuff(id)
{
    
calculateArray(values[id], 2);
    
client_print(idprint_chat"%d"values[id][0]);

The purpose of the stock is to allow me to shuffle and "shift" indexes for the array, but that doesn't really matter because I have more stocks like this. Just wanted to know how can I use sizeof inside the stock.

Thank you for your answer!
shauli is offline
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

Forum Jump


All times are GMT -4. The time now is 09:05.


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