Home  >  Q&A  >  body text

c++ - c语言库的数据一般如何存放?

高洛峰高洛峰2765 days ago633

reply all(4)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 13:30:27

    I think "global variables are not recommended in most books" should refer to most tutorial books. For beginners, global variables are an easy place to use incorrectly, so tutorial books do not recommend using global variables. variable. However, the use of global variables cannot be completely prohibited because of this. When used correctly, global variables can effectively reduce the complexity of development.

    Also, C and C++ handle global variables differently. C++ introduced the "class" encapsulation mechanism, thereby reducing the use of global variables, while C lacks a similar mechanism, so you will still see many examples of using global variables to save state in C.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:30:27

    What is written in the source code, how to put it after compilation.

    It’s just that the static library will be placed together with your program, while the dynamic library is its own separate space.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 13:30:27

    Not sure what question I want to ask.

    But since the glfw library is mentioned, it is an open source library. You can go directly to Github to see its source code.

    https://github.com/glfw/glfw

    In addition, let me say one more thing, general library-level code does not necessarily have a lot of data, and many of them just implement some calling logic and function combinations.

    Supplement:
    Regarding the issue of global variables in the code, in principle, we should avoid unnecessary or lazy use of global variables, but it is by no means disabling global variables. Because some variables really need to be known globally, especially some configuration parameter type variables. And many global variables are const, just to avoid causing program confusion.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:30:27

    Since the questioner raised this question, I suggest you take a look at the principles of Linux environment programming and compilation. The compilation process is actually divided into several steps. You should have covered them all when learning C language, including preprocessing and compilation. , assembly, and linking are basically these four steps. Preprocessing is a very simple lexical analysis, which replaces the preprocessing statement. Compilation means compiling it into assembly code. Of course, there is also direct compilation into binary code. Under normal circumstances They are all split into two-step compilation and assembly. After the assembly is completed, an o file will be generated, which is a binary object file. This is a binary file that contains all development codes, including complete text segments, data segments, and uninitialized data. Segments and other solidified binary codes. The final linking stage is to merge the binary code of the third-party library with the existing binary code, including merging other sections such as the text section.
    However, in almost all cases, we use third-party libraries, whether they are ISO C libraries or libraries provided by Unix. When writing code, we only include its header file, which is just for compilation. Syntax detection of the processor. The actual binary code of the library has been packaged into a static link library and a dynamic link library. The difference between the static link library and the dynamic link library lies in whether the actual binary code is merged during linking, or whether only a piece of boot code is merged. , in this way, whether the subject understands the question.

    reply
    0
  • Cancelreply