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

#define or new const


Post New Thread Reply   
 
Thread Tools Display Modes
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-22-2010 , 18:55   Re: #define or new const
Reply With Quote #11

Quote:
Originally Posted by Bugsy View Post
In this case, the question is whether or not a memory address occupies a cell of memory when a variable is used. If so there will be no difference between #define and const for integers.
Oh, good point. I had to read that 4 times to understand what you were saying lol .
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-22-2010 , 22:34   Re: #define or new const
Reply With Quote #12

I did a little testing with the 'total requirements #" at compilation with #define and const.

Arrays:
#define always results in a larger compiled plugin than const when the symbol\variable is used more than once. If used once, the size is identical.

Integers:
#define always results in a 4-byte smaller compiled plugin, regardless of the number of times the symbol\variable is used.

I also noticed the compiler will throw a warning if #define is used to define a variable with an incorrect type. I assumed otherwise in one of my posts above after reading a few discussions regarding this #define vs. const discussion on the web.

This will give a warning. set_user_gravity expects a float as the 2nd param.
PHP Code:
#define Test 55

set_user_gravityid Test ); 
__________________

Last edited by Bugsy; 07-22-2010 at 22:43.
Bugsy is offline
PattyBiena
BANNED
Join Date: Jul 2010
Location: Argentina
Old 07-22-2010 , 23:06   Re: #define or new const
Reply With Quote #13

Quote:
Originally Posted by Bugsy View Post
I did a little testing with the 'total requirements #" at compilation with #define and const.

Arrays:
#define always results in a larger compiled plugin than const when the symbol\variable is used more than once. If used once, the size is identical.

Integers:
#define always results in a 4-byte smaller compiled plugin, regardless of the number of times the symbol\variable is used.

I also noticed the compiler will throw a warning if #define is used to define a variable with an incorrect type. I assumed otherwise in one of my posts above after reading a few discussions regarding this #define vs. const discussion on the web.

This will give a warning. set_user_gravity expects a float as the 2nd param.
PHP Code:
#define Test 55

set_user_gravityid Test ); 
PHP Code:
#define Test 55
->
const Test 55 
PattyBiena is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-22-2010 , 23:11   Re: #define or new const
Reply With Quote #14

Quote:
Originally Posted by PattyBiena View Post
PHP Code:
#define Test 55
->
const Test 55 
What point are you attempting to make? Did you read the thread at all?
__________________
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-22-2010 , 23:19   Re: #define or new const
Reply With Quote #15

I don't suppose it would let you do #define float:55.0?

Quote:
Originally Posted by PattyBiena View Post
PHP Code:
#define Test 55
->
const Test 55 
lol
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-22-2010 , 23:29   Re: #define or new const
Reply With Quote #16

Quote:
Originally Posted by fysiks View Post
I don't suppose it would let you do #define float:55.0?
No, but that's not needed.

PHP Code:
#define Test 55.0

set_user_gravityid Test ); //Pre preprocessed
set_user_gravityid 55.0 ); //preprocessed 
__________________
Bugsy is offline
PattyBiena
BANNED
Join Date: Jul 2010
Location: Argentina
Old 07-23-2010 , 01:22   Re: #define or new const
Reply With Quote #17

But, is more better use define?
PattyBiena is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-23-2010 , 01:46   Re: #define or new const
Reply With Quote #18

Quote:
Originally Posted by PattyBiena View Post
But, is more better use define?
What is better than better, or worst than better, that is the question.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-23-2010 , 19:35   Re: #define or new const
Reply With Quote #19

Quote:
Originally Posted by PattyBiena View Post
But, is more better use define?
It is really a subjective matter when you use the ambiguous word "better" lol .
__________________
fysiks 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 02:00.


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