Improved generation in C for constant parameters

Vala generates C warnings following conversion to constant:

void teste(Vector2i position)
{
    Vector2i pos;
    pos = position;

    print("%d and %d\n", pos.x, pos.y);
}

struct Vector2i{
    int x;
    int y;
}

const Vector2i position = {42, 61};

void main()
{
    teste(position);
}

Screenshot_from_2023-02-15_17-06-45

it would be interesting to be able to do :

void teste(const Vector2i position);

which is still impossible today or we'll stay like this and try to make the cast in const more cleanly.

I also noticed that vala does not cause the warning when you do this:

const Vector2i position = {42, 61};

void main()
{
    Vector2i tmp = position;
    teste(tmp);  // no C warning
}

this could be done in the background, for my part I prefer a better implementation of constants in vala, because they are not really used except for define generation Here I let you debate :)

Edited Feb 15, 2023 by Ghost User
Assignee Loading
Time tracking Loading