Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • OK. But why does the same code compile successfully with clang++ 3.4 and g++ 4.8.2 (with -Wall -Wextra -pedantic-errors -std=c++03 flags)? Commented Oct 26, 2014 at 13:34
  • @Constructor Because C++ apparently has different rules for struct definition scope. Sorry, missed that bit in your question, and I can't quote the C++ standard for the rules. Commented Oct 26, 2014 at 14:01
  • There is no reason to apologize. I've added this piece of the question after your answer. It is sadly that you haven't a relevant quote from the C++ standard. But what about the C one? Commented Oct 26, 2014 at 14:06
  • 2
    @Constructor; C11 6.2.1 defines scope, especially p4 and p7 is relevant (function-prototype scope is what you're after). I currently fail to find the part where it's mandated that the forward-declaration works (and struct bar in the prototype doesn't declare a new type and hide the outer definition), though. Commented Oct 26, 2014 at 14:20
  • 1
    @mafso : Surely it works in C++ is because the first use is an implicit forward declaration and there is only one declaration? That being the case, there would not be an explicit mention regarding forward declaration overriding the implied declaration, because they were always the same. As the C warning says the behaviour is "probably not what you want", so in C++ it is fixed, probably because in C++'s design, compatibility with C was secondary to fixing some of C's semantic flaws. Commented Oct 26, 2014 at 15:43