Skip to content

Assignment of struct compound-literal doesn't work. #43

@Gontjarow

Description

@Gontjarow

The below program will output 0.000000 for all 6 values.

#include <stdio.h>

typedef struct xy
{
    double x, y;
} t_xy;

t_xy vec(double x, double y)
{
    return ( (t_xy){x, y} );
}

t_xy operator+ (t_xy &a, t_xy &b)
{
    return ( (t_xy){a.x + b.x, a.y + b.y} );
}

int main(int argc, char *argv[])
{
    t_xy a = vec(1, 2);
    t_xy b = vec(2, 4);
    t_xy c = a + b;
    printf("a == %f %f\n", a.x, a.y);
    printf("b == %f %f\n", b.x, b.y);
    printf("c == %f %f\n", c.x, c.y);
}

The same applies even to the simplest case:

t_xy test = (t_xy){1.0, 2.0};
printf("test == %f %f\n", test.x, test.y);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions