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

Add better array initialization #22

Closed
NeeEoo opened this issue Oct 25, 2020 · 0 comments
Closed

Add better array initialization #22

NeeEoo opened this issue Oct 25, 2020 · 0 comments

Comments

@NeeEoo
Copy link
Contributor

NeeEoo commented Oct 25, 2020

Currently if you want to set an array to have specific values you need to do this

int array[5];
array[0] = 40;
array[1] = 63;
array[2] = 15;
array[3] = 33;
array[4] = 76;

it would be better to be able to do this

int array[5] = {40, 63, 15, 33, 76};

or

int array[5];
array = {40, 63, 15, 33, 76};

(unsure if this is valid c)

The resulting code would probably look like this

[-]>[-]+++++[-<++++++++>]
>[-]+++++++[-<+++++++++>]
+++++++++++++++>[-]
+>[-]++++[-<++++++++>]
+>[-]+++++[-<+++++++++++++++>]

This should also support multi-dimensional arrays (This might be very hard to implement)
Example:

void main() {
    int array[2][5];
    int idx = readchar() - 48;

    if(idx == 0) {
        array[0] = {40, 63, 15, 33, 76};
        array[1] = {27, 122, 75, 23, 64};
    }
    if(idx == 1) {
        array = {
            {87, 45, 23, 12, 11},
            {1, 0, 9, 2, 12}
        };
    }
    if(idx == 2) {
        array = {
            13, 4, 98, 4, 7,
            22, 85, 43, 11, 52
        };
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant