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

Weird Tag Mismatch Using _:EnumName


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 03-28-2015 , 06:27   Weird Tag Mismatch Using _:EnumName
Reply With Quote #1

Hello. I've noticed this weird tag mismatch but am not sure if it's a bug or intended. Here's an example:

PHP Code:
enum MyEnum
{
    
ME_1,
    
ME_2
};

public 
OnMapStart()
{
    
ArrayList al = new ArrayList(_:MyEnum); // MyEnum equals 2 because it has two defined values.
    
    
MyEnum me[_:MyEnum];
    
al.PushArray(me); // Warning.
    
    
MyEnum me2[view_as<int>(_:MyEnum)];
    
al.PushArray(me2); // Warning.
    
    
const int MYENUM_SIZE _:MyEnum;
    
MyEnum me3[MYENUM_SIZE];
    
al.PushArray(me3); // No warning.

So _:MyEnum and view_as<int>(_:MyEnum) is not exactly an int, but when assigning it to an int variable/constant, it's converted to int. Should it be like this?
__________________
hleV is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 03-28-2015 , 07:21   Re: Weird Tag Mismatch Using _:EnumName
Reply With Quote #2

you can do:
PHP Code:
int enumSize[MyEnum]; //This restricts the array to last value of enum + 1, only allows values from the enum to be used for array indexes(for no warning), otherwise anything else causes a warning.
enumSize[ME_1] = 2
Example:
PHP Code:
enum Tester {
    
M1,
    
M2=500,
}

public 
void OnMapStart()
{
    
int eSize[Tester];
    
eSize[view_as<Tester>5] = 6;
    
eSize[M2] = 5;

Compiles into(Used SPEdit's lysis):
PHP Code:
public void OnMapStart()
{
    
int eSize[501];
    
eSize[20] = 6;
    
eSize[2000] = 5;
    return 
void 0;

__________________

Last edited by WildCard65; 03-28-2015 at 07:28.
WildCard65 is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 03-28-2015 , 07:58   Re: Weird Tag Mismatch Using _:EnumName
Reply With Quote #3

As you can see from my initial post I'm not really having a problem with making the code work as I made a workaround. The thing is, when calling method PushArray() and passing an array that was initialized with size taken from an enum tag, it produces a tag mismatch warning.
Your example doesn't solve anything as the warnings come from using functions with tag-sized arrays passed as arguments.

A little simpler example:

PHP Code:
enum MyEnum
{
    
ME_1,
    
ME_2
};

public 
OnMapStart()
{
    
MyEnum me[_:MyEnum];
    
Test(me); // Warning.
    
    
const int ME_SIZE _:MyEnum;
    
MyEnum me2[ME_SIZE];
    
Test(me2); // No warning.
}

void Test(const any[] array)
{
#pragma unused array

__________________

Last edited by hleV; 03-28-2015 at 08:00.
hleV 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:53.


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