Skip to content

Instantly share code, notes, and snippets.

@klange
Created April 9, 2021 02:10
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 klange/839d8904a5e7a1ac5f650e3eeb099356 to your computer and use it in GitHub Desktop.
Save klange/839d8904a5e7a1ac5f650e3eeb099356 to your computer and use it in GitHub Desktop.
#include <stdio.h>
struct Base {
int foo;
int bar;
};
struct Sub {
struct Base;
int baz;
int qux;
};
int main(int argc, char * argv[]) {
struct Sub sub;
sub.foo = 1;
sub.bar = 2;
sub.baz = 3;
sub.qux = 4;
return 0;
}
$ gcc -o test test.c
test.c:9:13: warning: declaration does not declare anything
9 | struct Base;
| ^
test.c: In function ‘main’:
test.c:17:5: error: ‘struct Sub’ has no member named ‘foo’
17 | sub.foo = 1;
| ^
test.c:18:6: error: ‘struct Sub’ has no member named ‘bar’; did you mean ‘baz’?
18 | sub.bar = 2;
| ^~~
| baz
$ gcc -fms-extensions -o test test.c
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment