-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sizeof for enums #44
Comments
You should use |
Ok, if Zeex says it's an unreasonable request I'll respect that. But very often I see people caught up with default values, for example strcat: native strcat(dest[], const source[], maxlength=sizeof dest); So strcat(Anything[0][StringValue], "Dickbutt"); Simply fails. |
There is a known issue with enum field and sizeof in this situation. It has been fixed in the Pawn 3.3.3930. This should be similar to this : Arkshine/amxmodx@a873066 |
I was thinking... could this possibly break something? From the language point of view, it seems totally fine to return 1 for @Y-Less what do you think? |
I've always seen "1" here as the correct return. This enum: enum X
{
A,
B[10],
C
} Is entirely equivalent to: enum X
{
A,
B,
C = B + 10
} Or: #define A X_tag:0
#define B X_tag:1
#define C X_tag:11
#define X X_tag:12 People would entirely expect "sizeof (B)" to return "1" there. "B" is just a subset of "X", asking for its size is asking for the size of part of an array, not the whole array, and with this patch not even an element of the array. Also, I have always said "enums are not arrays" - they are flattened by the compiler. Doing: new arr[X];
arr[B][3]; Is just fancy syntax for: new arr[X];
arr[B + X_tag:3]; I didn't comment on this earlier, as if a majority of people think it should be different (as even the later official versions of PAWN seem to think it should) then who am I to argue? But as I say, given everything here, I don't think it makes sense from a language point of view. And since you asked directly... |
I'm not sure we are talking about the same thing (patch is not about return of |
Indeed I also looked this up in newer Pawn sources, couldn't find Pawn 3.3.3930 referenced in Arkshine/amxmodx@a873066 but 3.3.4058 has it. I guess they knew what they were doing and had thought about possible backwards compatibility issues in advance. |
I can't actually think of a place where it would cause issues, at least not for YSI. To be fair, thinking about it more it might actually be better. |
OK, then there are apparently no drawbacks, plus it's in the official Pawn. Let's leave it here. |
I'm not certain how compiler handles enumerators, but sizeof doesn't bode well with hidden array sizes:
The text was updated successfully, but these errors were encountered: