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

Use enums as array indexes (tag mismatch error)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fakuivan
Senior Member
Join Date: Nov 2015
Old 07-06-2016 , 14:04   Use enums as array indexes (tag mismatch error)
Reply With Quote #1

PHP Code:
enum Test_SDKCalls
{
    
Test_IsActive 0,
    
Test_IsHibernating
    
/*...*/
}

char gs_calls[Test_SDKCalls][] = 
{
    
"CBaseServer::IsActive",
    
"CBaseServer::IsHibernating",
    
/*...*/

When I do gs_calls[Test_IsActive] I get a tag mismatch error. Is there any way to get around it (else than using view_as<int>(Test_IsActive))? How?
fakuivan is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-06-2016 , 16:10   Re: Use enums as array indexes (tag mismatch error)
Reply With Quote #2

enums don't have to be named. When you do name an enum, you'll get a tag mismatch if you try using it where you'd normally use an int.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 07-06-2016 at 16:11.
Powerlord is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 07-06-2016 , 19:05   Re: Use enums as array indexes (tag mismatch error)
Reply With Quote #3

: I didn't know about that one. Thanks Powerlord. btw why is it so hard to find documentation about enums?
fakuivan is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 07-07-2016 , 17:52   Re: Use enums as array indexes (tag mismatch error)
Reply With Quote #4

Quote:
Originally Posted by Powerlord View Post
When you do name an enum, you'll get a tag mismatch if you try using it where you'd normally use an int.
No, you get a tag mismatch warning (not an error, unless you -E) almost whenever you try to use a tag starting with an uppercase letter as anything else.

Indexing an array is not one of the things that will warn, though.

Not naming the enum means it doesn't start with an uppercase letter, but of course using a lowercase letter to start the name is an alternative.
Fyren is offline
Reply



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 18:16.


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