Skip to content

Weird behavior when a 3D array is initialized inside a 2D array #341

Open
@AGraber

Description

@AGraber

Is this a BUG REPORT, FEATURE REQUEST or QUESTION?:

  • Bug Report
  • Feature Request
  • Question

What happened:
The following code compiled with no error or warning whatsoever, and compiles to a rather strange result which gets demostrated below:

static const FCNPC_IdleAnims[][] =
{
    {"PED", "FLEE_LKAROUND_01"},
    {"PED", "DAM_ARML_FRMFT"},
    {"PED", "DAM_ARMR_FRMFT"},
    {"FLOWERS", "FLOWER_HIT"},
    {"KISSING", "GF_CARARGUE_02"}
};

main()
{
    printf("%s, %s", FCNPC_IdleAnims[3][0], FCNPC_IdleAnims[3][8]);
    return 1;
}

output:

FLOWERS, FLOWER_HIT

What you expected to happen:
Not compile at all and throw an error about array dimensions

How to reproduce it (as minimally and precisely as possible):
Compile the code above and run it

Anything else we need to know?:
Shoutout to Riddick#6416 (Riddick94 at SA-MP Forums) for discovering this.

Environment:

  • Operating System
    Windows 10
  • Compiler version
    Tested on 3.10.4, 3.10.7 and 3.10.8
  • How are you invoking the compiler? Pawno, Sublime, vscode, sampctl or command-line?
    sampctl
  • If using sampctl, the version number
    1.8.19

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions