Score:0

gcc-10 (10.3.0) does not handle anonymous struct correctly?

br flag
A L
$ gcc-10 --version
gcc-10 (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0

$ cat test.c
struct A {
    int a;
};

struct B {
    int b;
    struct A;
};

int main(void)
{
    struct B c;
    c.a = 0;
    c.b = 1;
    return 0;
}

$ gcc-10 test.c
test.c:7:13: warning: declaration does not declare anything
    7 |     struct A;
      |             ^
test.c: In function ‘main’:
test.c:13:6: error: ‘struct B’ has no member named ‘a’
   13 |     c.a = 0;
      |      ^

Adding -std=c17 does not make any difference. I checked (with the -v option that cc1 gets called from the correct location (/usr/lib/gcc/x86_64-linux-gnu/10/cc1 ). The source should compile, though. gcc 10.2.0 (used on Cygwin, for example), is perfectly able to deal with this code:

$ gcc --version
gcc (GCC) 10.2.0
$ gcc test.c
$

(no errors).

This is what was installed as "gcc-10":

cc-10-base/focal-updates,focal-security,now 10.3.0-1ubuntu1~20.04 amd64 [installed,automatic]
gcc-10/focal-updates,focal-security,now 10.3.0-1ubuntu1~20.04 amd64 [installed]
libgcc-10-dev/focal-updates,focal-security,now 10.3.0-1ubuntu1~20.04 amd64 [installed,automatic]

My system:

$ uname -a
Linux xxx 5.11.0-25-generic #27~20.04.1-Ubuntu SMP Tue Jul 13 17:41:23 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Any help will be greatly appreciated!

Thanks!

galexite avatar
pk flag
I think this is a question for StackOverflow, not AskUbuntu.
Score:0
br flag
A L

Looks like -fms-extensions is implicitly defined under Cygwin, so adding it explicitly to the gcc command on Ubuntu solves the problem.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.