Hello. I am a beginner, I would like to ask a question. There is an announcement:

extern BOOL ttt, key; 

Why extern is chosen is not entirely clear What is it?

    2 answers 2

    This means that the memory for these variables is allocated in some other .cpp file. Those. To successfully link a project, it is necessary that in one of the .cpp files of the project there was a declaration of variables without extern.

    • one
      More precisely, not necessarily .cpp. Name data definitions must be present either in the object file or in the library when linking. (Well, for simplicity, we omit the options with executable-linkable formats). "One of the .cpps" is actually one of the options for ensuring such a presence. - alexlz 6:36 pm
    • This is true, but I did not want to confuse the answer to the question :-) - ganouver
    • > memory for these variables is allocated in some other .cpp file. The memory is variable not allocated in files. In files, variables are declared and defined. In this case, the variable must be defined once per translation unit. - IAZ

    extern is a memory class modifier. It makes the described object or function global - available in all files of the program.

    Why is extern chosen here? Well, one line does not understand this, it means there was a need.