Preliminary definition of an incomplete type structure

Consider the following as a C file:

static struct S a;

int main() {
  return (long)&a;
}

struct S {
  int b;
} s;

Based on my reading of the C11 spec , I find this behavior undefined. 6.9.2 status:

The declaration of an identifier for an object with a file area without an initializer and without a storage class specifier or with a static storage class specifier is a preliminary definition.

and under the heading Semantics (no Limitations):

If the declaration of an identifier for an object is a preliminary definition and has an internal relationship, the declared type should not be incomplete.

, a , struct S . , , undefined.

GCC --std=c11 -Wall -pedantic. , GCC undefined?

+4
1

, undefined.

Undefined - , , . . , gcc . , , .

+3

Source: https://habr.com/ru/post/1696229/


All Articles