Comments (9)
You should use sizeof Anything[][StringValue]
from compiler.
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.
from compiler.
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
from compiler.
I was thinking... could this possibly break something? From the language point of view, it seems totally fine to return 1 for sizeof Anything[0][StringValue]
since enums are just array indices IIRC.
@Y-Less what do you think?
from compiler.
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...
from compiler.
I'm not sure we are talking about the same thing (patch is not about return of sizeof Anything[0][StringValue]
, also it should not possible to do that, I mean with 0), but how is handled an enum internally is irrelevant to the fact that if you use an enum as a "structure", you would want to expect sizeof B
returns 10
and not 1
. You're asking sizeof of an array not the index in the internal flat array. Enum in Pawn is an ugly hack for sure.
from compiler.
Indeed sizeof Anything[0][StringValue]
doesn't compile outside of function calls. I was worried that this might have been used in some parts of YSI or perhaps other libraries.
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.
from compiler.
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.
from compiler.
OK, then there are apparently no drawbacks, plus it's in the official Pawn. Let's leave it here.
from compiler.
Related Issues (20)
- Stop Compiler
- Samp includes error HOT 1
- Packed string access in enum arrays
- Optimization of conditional expressions
- Can't compile on linux! HOT 2
- when to wait for the next build? HOT 1
- Classes and objects in PAWN? HOT 3
- Compiler giving false positive warnings (240) HOT 4
- Named only parameters. HOT 3
- External natives are always in the header, even when not used. HOT 2
- Constant "Run time error 19: "File or function is not found"" error
- default include path for standard libraries? HOT 1
- The Application was unable to start correctly.(0xc000007b) HOT 1
- fatal error 100: cannot read from file: "Pawn.CMD" HOT 1
- fatal error 100: cannot read from file: "interception"
- [DIY] Build from source on Apple Chip M1 using rosetta2 HOT 6
- `initialization data exceeds declared size` when using progressive initialization with an array size 1
- `const` can be specified for a function argument more than once
- error compile
- pawnc reports wrong filenames and line numbers on warning number 203 & 213
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compiler.