Giter Club home page Giter Club logo

Comments (9)

Arkshine avatar Arkshine commented on August 18, 2024

You should use sizeof Anything[][StringValue]

from compiler.

Misiur avatar Misiur commented on August 18, 2024

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.

Arkshine avatar Arkshine commented on August 18, 2024

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.

Zeex avatar Zeex commented on August 18, 2024

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.

Y-Less avatar Y-Less commented on August 18, 2024

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.

Arkshine avatar Arkshine commented on August 18, 2024

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.

Zeex avatar Zeex commented on August 18, 2024

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.

Y-Less avatar Y-Less commented on August 18, 2024

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.

Zeex avatar Zeex commented on August 18, 2024

OK, then there are apparently no drawbacks, plus it's in the official Pawn. Let's leave it here.

from compiler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.