C language collection

Source: Internet
Author: User

1. the const modifier in const C language, which is less disgusting than C ++, is used to modify the const attribute of a variable. Variables modified by const in C language have read-only attributes and cannot be modified. Variable modified by const! = Constant. Although the variable modified by const cannot be modified, it is essentially different from the constant. Initialization is required when defining a variable of the const type. Of course, Initialization is not required when the const is used as a function parameter. 1.1 Compiler Optimization on const variables: the compiler usually saves them in the symbol table instead of allocating storage space for common const Read-Only variables, which makes it a value during compilation, without the storage and read memory operations, the efficiency is also high. The read-only variables defined by const only provide the corresponding memory address from the assembly point of view, rather than the number of immediate values like # define. Therefore, the read-only variables defined by const have only one copy during the program running (because they are global read-only variables and are stored in the static zone ), # The macro constant defined by define has several copies in the memory. # The define macro is replaced during the pre-compilation phase, while the read-only variable modified by const is determined during compilation. # The define macro has no type, while the read-only variable modified by const has a specific type. 1.2 When typedef encounters a variable modifier (const), copy the code typedef struct student {/* code */} Stu_st, * Stu_pst; 1) const Stu_pst stu3; 2) Stu_pst const stu4; for stu3 and stu4 defined by the replication Code, are their types the same? The answer is the same. Why? In this case, we cannot assume that typedef is the same as # define and can be expanded directly. In fact, because the const modifier is the variable itself, the typedef type in const is considered as a type without considering the type, that is, the typedef type in 1) and 2, instead of being expanded. So the above is equivalent to: const type var type const var that is to say, const modifies the variable var. 2. the rare volatile keyword is a type modifier like const. It uses its variable to indicate that it can be changed by unknown factors in some compilers, such as operating systems, hardware, or other threads. When the variable declared by this keyword is encountered, the compiler will not optimize the code that accesses the variable, so as to provide stable access to the special address. 3. struct 3.1 flexible array, also known as zero-length arrays, is a feature added to C99. A flexible array can be defined as follows: copy the code struct line {int length; char contents [] ;}; struct line * thisline = (struct line *) malloc (sizeof (struct line) + this_length); thisline-> length = this_length; copy the code in ISO C90 and define a flexible array (there is no concept of a flexible array in the C90 Standard) contents [] must be defined as contents [0], where 0 is required. In ISO C99, a free array member can be defined directly in the struct. the syntax of the Free array is as follows: the length of the Free array member is 0. when defining the number of an array, 0 in [] is not included. The free array members are not completely of the type. Therefore, when the sizeof operator is used for the struct, the size of the Free array members is not included. At least one member must be defined before a free array, you cannot define only one free array in a struct. If a struct contains a free array or a consortium contains this struct, the struct or consortium cannot be a member of the struct or an array. For GCC's support for flexible arrays, visit this website: http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html#Zero-Length 4. When parsing an expression, the greedy rule for such an expression: What exactly does a ++ B represent? Is it a + (++ B) or (a ++) + B? In this case, we need to consider how the C language parses the syntax analysis. When the C language compiler performs syntax analysis, the greedy rule is used. That is to say, when processing the expression, if the current character can form a meaningful symbol with the previous string, it will continue to read the next character until it cannot form a meaningful character. That is to say, after the above expression is parsed TO a +, it encounters +. At this time, because a ++ is legal in C, it continues to process the next +, because a ++ is invalid in C, it is not used as a part of the expression. That is to say, the above expression is parsed as: (a ++) + B. 5. Some commands that can be used for preprocessing during compilation are used to output some useful information during compilation, so as to facilitate tracking the compilation process and control compilation. # Line // change the current row number and file name. The basic syntax is as follows: # line number ["filename"] # error // when compiling a program, if # error is encountered, a compilation error message is generated and compilation is stopped. The compiler predefines some macros during the compilation process to output some information about the compilation process: _ LINE _ // The number of the row being compiled by the compiler _ FILE _ // The variable FILE Name of the compiler _ TIME _ // The Compilation TIME _ STDC _ // determine whether the FILE is defined as a standard C program

Related Article

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.