Some mystic with an extern pointer for a structure in C

I have the following code snippets with 3 global structure pointers:

structs.h:

#pragma once

typedef struct Bignum {
  int digit;
  struct Bignum *next;
  struct Bignum *prev;
} Bignum;

typedef struct Stack {
  struct Bignum *head;
  struct Bignum *tail;
  char sign;
  struct Stack *next;
} Stack;

Bignum *num_tail;
Bignum *num_head;
Stack *stack_head;

globals.c:

#include "structs.h"

Bignum *num_tail;
Bignum *num_head;
Stack *stack_head;

When I compile them with other .c files (where I include structs.h and work with num_tail, num_head and stack_head), compilers (both clang version 3.8.0 and gcc 5.4.0) compile this code without errors and the program works as it should. But, as far as I know, this code should not compile and work properly due to the lack of a modifier externin structs.h. Why does it work? :)

UPD: Yes, the answer is an indicative definition . Indeed, after initializing pointers to NULLcompilers, an error message is issued. Thanks for all the answers!

+4
2

. , . ={0}; , . , . , , . ( C nm output), , . ( , extern .)

+4

extern, .

globals.c .

Bignum *num_tail;
Bignum *num_head;
Stack *stack_head;

, , num_tail .

+1

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


All Articles