Skip to content
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

[Doc Improvement] Not obvious how to define Array of Arrays #1789

Open
1 task
lukasjuhrich opened this issue Jul 2, 2024 · 4 comments
Open
1 task

[Doc Improvement] Not obvious how to define Array of Arrays #1789

lukasjuhrich opened this issue Jul 2, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@lukasjuhrich
Copy link

Operating System

Linux

What's the issue you encountered?

Conceptually, I'm having a pattern like this:

import std.array;
struct File {
    u8 dim1, dim2;
    std::Array<std::Array<u8, dim1>, dim2> cells;
};

File file @ 0x00;

this results in No variable named 'dim1' found.

How can the issue be reproduced?

Create a file with the contents

const uint8_t data[6] = {
    0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 
};

and use the pattern above.

Error vanishes when replacing the inner dim1 by 2 .

ImHex Version

1.35.3

ImHex Build Type

  • Nightly or built from sources

Installation type

Arch package

Additional context?

Version: 1.35.3
Commit: v1.35.X@dffb7e9
Build time: Jun 29 2024, 19:35:52
Type: Installed

@lukasjuhrich lukasjuhrich added the bug Something isn't working label Jul 2, 2024
@paxcut
Copy link
Contributor

paxcut commented Jul 2, 2024

I don't think that's a bug. The inner Array doesn't have direct access to the variables of the File struct. You can use the parent keyword to access the variables of the parent. The following code works in the example you wrote:

import std.array;
struct File {
    u8 dim1, dim2;
    std::Array<std::Array<u8, parent.dim1>, dim2> cells;
};

File file @ 0x00;

@lukasjuhrich
Copy link
Author

You can use the parent keyword to access the variables of the parent.

I've been looking for something like that, thanks!
So let's consider this a documentation bug – a line like this would be very helpful in the documentation of std::array. These docs claim that Array<T, Size> can be used to build multi-dimensional arrays, but does not provide an example for how to achieve that.

@paxcut
Copy link
Contributor

paxcut commented Jul 3, 2024

Would you consider perhaps a change in the title? That would help users seeking answers.

@lukasjuhrich lukasjuhrich changed the title [Bug] Array of Arrays cannot use variable in inner array [Doc Improvement] Not obvious how to define Array of Arrays Jul 3, 2024
@lukasjuhrich
Copy link
Author

Would you consider perhaps a change in the title?

Sure, hope this is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants