Raised This Month: $51 Target: $400
 12% 

Get sizeof array in a macro


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
shauli
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-21-2018 at 17:48.
shauli 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 21:18.


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