Raised This Month: $ Target: $400
 0% 

Constant Expression


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 04-19-2006 , 16:28   Constant Expression
Reply With Quote #1

Why doesn't this work

Code:
new f[2] = {params[0], SOME_DEFINE}

where

Code:
#define SOME_DEFINE 0 new params[1] params[0] = 3

Gives me this error

Code:
error 008: must be a constant expression; assumed zero
---

BONUS QUESTION:

Can you use any kind of pointer in Pawn, exept for the pass by reference when working with functions?
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 04-19-2006 , 17:15   Re: Constant Expression
Reply With Quote #2

Well, the error message basically explains it:
You may only use constant expressions for such initializer lists.
i.e no "normal" variables.
Either use all constants, or first declare the array and then assign the non-constant things separately.



Pointers... well, you could hack together some semi-pointers by mixing up byref and byval with callfunc stuff.

Code:
#include <amxmodx> public helper_getptr(x) {    return x; } public helper_deref_read(&x)   // was that the syntax for byref variables? {    return x; } public helper_deref_assign(&x, val) {    return (x = val); } #define getptr(%1) (callfunc_begin("helper_getptr"),callfunc_push_intrf(%1),callfunc_end()) #define deref_read(%1) (callfunc_begin("helper_deref_read"),callfunc_push_int(%1),callfunc_end()) #define deref_assign(%1,%2) (callfunc_begin("helper_deref_assign"),callfunc_push_int(%1),callfunc_push_int(%2),callfunc_end()) public mwah() {    new hello = 10;        new gaben = getptr(hello);    new hello_pm = deref_read(gaben);    server_print("Should be 10: %d", hello_pm);        deref_assign(gaben, 20);        server_print("Should be 20: %d", hello);    server_print("Should be 10: %d", hello_pm); }

I just hacked this together and haven't tested it (only compile), but you get the idea. So it may not work, maybe I made typos, maybe the comma operator is broken (i doubt that though), whatever. But you get the idea ;)

Of course, this is neither very useful nor effective performance-wise (actually, it'll have pretty awful performance)

EDIT: In fact, it turns out that BAIL has added get_addr_val, get_var_addr, set_addr_val to core. You might want to check them out in the funcwiki. Still I'm leaving my code here because I had some good fun writing it.
__________________
hello, i am pm
PM is offline
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 04-19-2006 , 17:31  
Reply With Quote #3

Thanks PM

I was trying to improve performance with a pointer to avoid copying a 256 char string.

I will certainly look for the functions you mentioned.
But first I'll have a good night of sleep
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 04-19-2006 , 17:36  
Reply With Quote #4

Quote:
Originally Posted by MaximusBrood
Thanks PM

I was trying to improve performance with a pointer to avoid copying a 256 char string.

I will certainly look for the functions you mentioned.
But first I'll have a good night of sleep
make it global i guess
as arguments, arrays are always passed by reference automatically
maybe you want to share it between plugins? that wouldn't work even with this "pointer" stuff because these are really addresses into the plugin's memory..

Hmm, more info please
__________________
hello, i am pm
PM is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 04-19-2006 , 19:21  
Reply With Quote #5

I'm the one that asked for the address hacking tools XD

The best method for doing this though, would be MemHack, as you can get the actual address.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
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 05:01.


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