Skip to content

Instantly share code, notes, and snippets.

@yyasuda
Last active January 14, 2023 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yyasuda/bb6c0ad6ffcbf6a526d775c360398a98 to your computer and use it in GitHub Desktop.
Save yyasuda/bb6c0ad6ffcbf6a526d775c360398a98 to your computer and use it in GitHub Desktop.
The initializer of a structure variable can include a reference to itself
/*
LLVM reports a warning as follows;
"variable 's' is uninitialized when used within its own initialization [-Wuninitialized]"
But it shows the answer "3" correctly.
*/
#include <stdio.h>
typedef struct {
int a, b, c;
} S;
int sum(S s) {
return s.a + s.b;
}
int main() {
S s = {1, 2, sum(s)};
printf("%d %d %d\n", s.a, s.b, s.c);
return 0;
}
@yyasuda
Copy link
Author

yyasuda commented Jan 14, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment