Re: [PATCH v5 12/15] strmap: enable allocations to come from a mem_pool
- From
Chris Torek <chris.torek@gmail.com>
- Date
- Nov 11, 2020, 20:34 UTC
- Message-ID
- <CAPx1GvfXMnhgQDan7N=Y4WWdcS6p6WrekYkDyfx4nwnDtSuMQQ@mail.gmail.com>
- In-Reply-To
- <20201111190121.GE9902@coredump.intra.peff.net>
On Wed, Nov 11, 2020 at 11:02 AM Jeff King <peff@peff.net> wrote:
> Even if we're only using a pointer to it, we still need a valid forward > declaration [in a function, but not in a struct definition] ... > I'm not sure whether this is a seldom-seen corner of the C standard, or > a compiler-specific thing (though both clang and gcc seem to allow it).
It is standard (and not all *that* seldom-seen, in that many compilers have warnings when you put these in function prototype scope). The forward declaration is implicit, and occurs *in the current scope*. The trick is figuring out what the scope is. At file level, the scope is "level zero" as it were: file scope. So it's as global as we get (C separates "globality" into scope and linkage; *variables* have linkagebut *type names* do not). Function prototypes, however, have function-prototype scope, which ends at the end of the function declaration.
Overall, though, I agree that the nicest style is to have an explicit forward declaration (in C that is—note that in C++, struct is just a class with everything public, and class definitions have scope!).
Chris