14.1 (conspect) Strings

Stages of converting a program in C to binary:

  1. .c → (preprocessor / cc -E) → .c

  2. .c → (translator / cc -S) → .s

  3. .s → (assembler / cc -c) → .o

  4. .o → (linker / cc or ld …) → binary

It creates not only code, but also possible functions, adds a main call, and stack protection.

Graph of dependency

Let's say the project consists of several files in C, then the entire structure of the binary build becomes inconvenient.

Example:

  1. Output function in a single file
  2. In another file, call the function

So you can compile both files and get the output. This is inconvenient because when there are a lot of them, it's a long operation and you don't always need to compile everything. If we want to compile a particular one separately, we bring all of them to the state of the objective and build the binary. If we edit only one of these two files, we need to compile it again, otherwise the object file will consist of the old ones, but when we update one, we only need to recompile it. Therefore, for convenience, you need to create a dependency graph.

Dependency graph- graph of files, which consists of files that each file goes and by what method it is obtained. Thus we use graph to rebuild faster, so that you can immediately see which file needs to be compiled again.

Makefile

There are in Makefile:

  1. Target
  2. Sources
  3. Recipe

Example:

We get a dependency chain and if the main file requires updating, the entire chain is updated. The build is defined automatically: it goes in any order and is self-defined, and the Make uses only the time.

Best example of realization:

   1 JUNK=*~ *.bak *.old
   2 GENERATES=*.o prog
   3 all:    prog
   4 
   5 prog:   f1.o f2.o
   6         cc $^ -o $@
   7 
   8 f1.o:   f1.c
   9         cc $< -c
  10 
  11 f2.o:   f2.c
  12         cc $< -c
  13 
  14 clean:
  15         rm -f $(JUNK) $(GENERATES)

Strings

Important

There no such data type as strings

As it usually works as an integer. There are special string converters and you can't put a Strings on the stack.

HSE/ProgrammingOS/14_Strings/Conspect_en (последним исправлял пользователь VasilyKireenko 2020-03-20 20:13:16)