I'm just starting to learn C, so hopefully this is not a dumb question. The problem I am facing is regarding header files and using #define for constants. I read that I should use the following to prevent my header from compiling more than once.
#ifndef NAME_OF_FILE #define NAME_OF_FILE . . //my header file content . #endif
I want to add a constant, and I believe that I would also use #define, for example
#ifndef NAME_OF_FILE #define NAME_OF_FILE #define NUM_CONST 5 //the constant I want in my header file . . . #endif
How does C know that #define NAME_OF_FILE refers to a .h file, and #define NUM_CONST 5 is just a constant? Is it because of the value at the end of NUM_CONST? Or am I all of this completely wrong?
. #define NAME_OF_FILE #define NUM_CONST 5 - . ( ).
#define NAME_OF_FILE
#define NUM_CONST 5
, :
printf("%d\n", NAME_OF_FILE NUM_CONST NAME_OF_FILE);
:
printf("%d\n", 5);
. "". , , " ".
NAME_OF_FILE .h, , ifndef .
NAME_OF_FILE
.h
ifndef
. NAME_OF_FILE .
#ifndef PRETTY_PINK_PRINCESS #define PRETTY_PINK_PRINCESS /* definitions */ #endif
. NAME_OF_FILE - , .
#define IDENTIFIER #ifdef, , , .
#define IDENTIFIER
#ifdef
,
#define NAME_OF_FILE int main() { int x = NAME_OF_FILE; }
int main() { int x = ; }
, "", , .
( #define NAME_OF_FILE NAME_OF_FILE, , , .)
#define NAME_OF_FILE NAME_OF_FILE
#define NAME_OF_FILE #define NUM_CONST 5
, , "NAME_OF_FILE" , . , , , , , . , "c-" , marco __TEST_H, , , "test.h". , , , , IDE , , IDE . , , ( , ), , .
Source: https://habr.com/ru/post/1668339/More articles:Native JavaScript vs. jQuery - real performance versus theoretical benchmarks - performancesml понимание функций - smlHow to change the style of Stroustrap C in emacs - emacsIs there a way to pass a variable to schematron? - xmlTrying to send data from html form and Node.js - javascriptif the instruction does not work and is skipped to another part - c ++Десятичное значение для двоичного кода в С++ - c++How to access an instance of a view model in the XAML page code behind (Xamarin Forms) in Prism - mvvmBenefit Coproduct over “sealed trait”? - scalaWhat is an elegant way to return a list index in python without looping? - pythonAll Articles