D
D
Dmitry Korolev2021-09-01 05:34:48
C++ / C#
Dmitry Korolev, 2021-09-01 05:34:48

How to use one state of header file variables in several program source files?

I have a header file with variables, types, prototypes and functions.
How to use it in multiple source files of a cs program?
It turns out that the preprocessor will expand the content in each source file that defines the include for this header?
if I remove the inclusion from the second file, then I get the absence of definitions, and if I leave it, I get an error that these definitions are already in the first file.
How to properly configure the compiler so that it goes from the calls of the second file to the definitions of the inclusion substitution in the first one. Roughly speaking, these definitions should be common to both files.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wataru, 2021-09-01
@adressmoeistranici

I understand that the problem is with global variables?
In the header you declare the variable as extern, in one c file you define it with initialization without extern - then everything works.

V
Vasily Demin, 2021-09-01
@includedlibrary

#pragma once

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question