sourcepawn icon indicating copy to clipboard operation
sourcepawn copied to clipboard

Allow to set a default value for enum struct members

Open DaBultz opened this issue 6 years ago • 4 comments

Most languages allow to set a default variable inside an enum, however SP does not. allowing a default variable as shown below could help to reduce the lines of code and make bugs less likely to occur because the developer forget to set the default values.

Exmaple:

enum struct Team {
    int score = 0;
}

DaBultz avatar Nov 29 '19 16:11 DaBultz

SourcePawn zero-initializes everything by default (excluding the "decl" keyword which is deprecated). If that's not happening for enum structs it's a bug.

dvander avatar Nov 29 '19 18:11 dvander

It's probably about default values different from 0.

peace-maker avatar Nov 29 '19 18:11 peace-maker

Confirmed that enum structs are zeroed by default, so marking this as a feature request. I like the idea, I'll start on it in early 2020.

dvander avatar Dec 02 '19 08:12 dvander

It's probably about default values different from 0.

Yup, that was what i meant. wasn't aware that enum structs were zeroed by default

DaBultz avatar Dec 05 '19 20:12 DaBultz