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

Marking enum as implicit-int


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 05-07-2018 , 03:01   Marking enum as implicit-int
Reply With Quote #1

Was wondering if it's possible to mark an enum as being an implicit-int (allowing implicit conversions to int) without having to make the first character lowercase. Someone mentioned that in regular pawn you could do something like this:
PHP Code:
enum _:EnumName 
But the SourcePawn compiler doesn't like that. Gives error "cannot tag an enum as implicit-int". The workaround I'm doing is naming it with a lowercase first character but it sort of triggers me since everything else in the file is named differently. I find it quite dumb that the behaviour of an enum would depend on it's name.

Last edited by hmmmmm; 05-07-2018 at 03:02.
hmmmmm is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-07-2018 , 05:33   Re: Marking enum as implicit-int
Reply With Quote #2

You can append a colon after the name which will disable all of the special Pawn enum magic, but the correct thing to do is really to make it lowercase.
__________________
asherkin is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 05-13-2018 , 08:31   Re: Marking enum as implicit-int
Reply With Quote #3

Tried the appending colon thing and doesn't seem to work, it becomes a part of the name then when I try to use it it gives various other errors. Is this what you mean by that?
PHP Code:
enum EnumName
Putting a space between the EnumName and the colon also fails to compile.

I know making it lowercase is correct way to do it but I'd really rather not. It makes the enum name look really out of place with my other code. The way I do naming is types start with capital letters and regular variables start with lowercase.

Last edited by hmmmmm; 05-13-2018 at 08:34.
hmmmmm is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-13-2018 , 08:35   Re: Marking enum as implicit-int
Reply With Quote #4

Yes that is it, but when doing that the name doesn’t exist as a symbol any more, the enum becomes just a bunch of integer constants.
__________________
asherkin is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 05-13-2018 , 08:58   Re: Marking enum as implicit-int
Reply With Quote #5

I see, but still gives the tag mismatch error when trying to use it with the SetNativeArray function and also doesn't let me use the strings in the enum array ("cannot coerce any[] to char[]; storage classes differ") so doesn't really fix my use case.

I'll just bite the bullet and leave it as lowercase, thanks for the help.

Last edited by hmmmmm; 05-13-2018 at 09:00.
hmmmmm 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 11:09.


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