"Linux C Programming One-stop learning" read notes (2):

Source: Internet
Author: User
Tags strtok

Pretreatment

#和 # #是两个预处理运算符 (note the operator that is not a C-language expression), #后接形参 (the middle can be a space) for creating string literals; # #用于连接两个形参.

Functional macro definitions can also have variable parameters, which is also used ... Represents a mutable parameter, and the part of a variable parameter in a macro definition is represented by _VA_ARGS_. Such as:

#define SHOWLIST (...) printf (#_VA_ARGS_)

Canceling a macro definition with #undef, canceling an undefined macro is not an error.

The compilation of conditional preprocessing (#if ... #elseif ... #endif), the optional method is: 1, manually edit the code, add the definition of the target macro, 2, in all the source files need to be configured to include a header file, in the header file to define the target macro; 3, via GCC- The D option defines the target macro 43 at compile time.

The C standard specifies a few special macros that are not defined to be used, most commonly _file_ (expanded to the current source file name) and _line_ (the line number of the current line of code).

The C99 Standard introduces a special identifier _FUNC_ can represent the current function name, which is a variable name (string variable) instead of a macro definition.

21st Chapter Makefile Foundation

The make program automatically reads the makefile file in the current directory (find the name Gnumakefile, makefile, and makefile, which is generally recommended for file names with makefile).

Make executes a command with @, then does not display the command itself and only displays the output, plus--, even if the command goes wrong, continue to execute the following command.

The common target names in Makefile are: All (perform compilation, usually default), install (perform post-compilation installation work, copy executable files, configuration files, documents, etc. to different installation directories), clean (delete compiled binaries), Distclean (not only delete the binaries, but also delete the other build files).

Make,: = The variable is encountered when assigned to expand immediately;? = when the assignment is not defined, it is defined and assigned (not immediately expanded), and if it is defined, nothing is done, and + = is used.

The-m option of GCC automatically parses the dependency of the target file and the source file.

22nd Chapter Pointers

GCC assigns string literals to the. Rodata segment, so the string literal is best understood as a const char* type when it is the right value.

In GdB, you can either add command-line arguments (starting with arg[1] after the run or start command, or you can use the set args command to run the program with run or start.

If the two-level pointer is outgoing, there may be two situations: 1, the outgoing pointer points to static memory, or to the allocated dynamic content, 2, dynamically allocates memory in the function, and then the outgoing pointer points to the memory.

23rd Chapter Function Interface

callback function

If the argument is a function pointer, the caller can pass the address of a function to the implementation of the callback function, that is, the caller provides a function but does not call it by itself, but instead lets the implementation of the callback function invoke it by using the callback function.

A callback function can implement functions similar to C + + virtual functions or generic algorithms.

The va_list type of the C standard library and the Va_start, Va_arg, va_end macros are all defined in the Stdarg.h header file for handling mutable parameters. The following example can be used to see the specific usage:

#include <stdio.h> #include <stdarg.h> void printlist (int begin,...) {      va_list ap;      char *p;      Va_start (ap,begin);      P=va_arg (Ap,char *);              while (p!=null) {            fputs (p,stdout);            Putchar (' \ n ');            P=va_arg (AP, char*);      }      Va_end (AP);} int main (void) {      printlist (0, "Hello", "World", "foo", "Bar", NULL);      return 0;}

24th C Standard Library

The C standard library provided by Linux platform includes: 1, a set of header files, defines many types and macros, declares many library functions and global variables, 2, a set of library files, provides the library function and the definition of variables.

Split string:

Char *strtok (char *str, const char *delim); Char *strtok_r (char *str, const char *delim, char **saveptr);

Strtok will constantly modify the value of STR while using a static variable in the function to remember where the string is processed, which makes the strtok non-reentrant. Instead of using a static variable, STRTOK_R requires the caller to pass the processing position to it as the third argument. The R in Strtok_r represents Reentrant (reentrant). There is a good example of using strtok_r in the man page.

"Linux C Programming One-stop learning" read notes (2):

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.