With the following:
typedef struct Person_ { char* name; char* parents[2]; } Person; int main(void) { Person jack = {.name="Jack", .parents={"Jim", "Julia"}}; Person tom = {.name="Tom", .parents={"Terry", "Tina"}}; Person friends[2] = (Person[2]) {jack, tom}; }
I get this error:
error: array initialized from non-constant array expression
Person friends[2] = (Person[2]) {jack, tom};
I know that I can initialize friends
as:
Person friends[2] = {jack, tom};
But why isn't it possible to annotate the type on the right side with an array like I would be able to (though redundantly) with another type such as:
int x = (int) 4; char *y = (char*) "Hi"; // invalid // int z[2] = (int[2]) {1,2};
https://stackoverflow.com/questions/66084034/specifying-type-of-array-on-right-side-of-expression February 07, 2021 at 10:31AM
没有评论:
发表评论