Installing using the VSS plugin under Eclipse (myeclipse)

Source: Internet
Author: User
Tags function prototype

One, scope, link properties, and storage type:

1. Scope: Common scopes have blocks of code, files, functions, and prototype scopes (only applicable to parameter names declared in a function prototype).

2. Link Properties:

A) links can bring multiple target file chains to the final target file. The Link property is the decision on how to handle identifiers that appear in different files .

b) There are three types of link properties: External (external), internal (internal), and none (none). Identifiers are generally external or non-attribute by default, but with the static keyword, you can change the attributes of identifiers, transform external properties into internal properties, and generally we call internal and external link properties relative to the file scope.


By default, the link property in B,c,f is external, the other is a non-link property, and f is an external function.

The "supplemental" extern keyword lets you specify that an identifier is from an external source file, that is, you can change the original internal or non-link property to an external link property. We can consider a more complicated case, that is, when the internal and external link property scope of the same identifier, the identifier of the link property how to choose?

For example, when the extern keyword is used for an identifier I and attempts to change its Link property, it is invalidated at this point, that is, it does not change the previously existing link property .

c) Storage type:

I. The storage type of a variable is the type of memory that stores the value of the variable, which feels when the variable is created, when it is destroyed, and how long its value can be saved. In large classes, there are two places where variable values can be stored: normal memory and hardware registers . Depending on the memory partitioning diagram below, the areas where the variables can be stored are: static, Heap, and stack areas.

Note that the variables that exist in the static zone are mainly global variables and Automatic variables that are converted by the static keyword , and it is worth noting that constants are also stored in static areas. We can deliberately analyze the case where the automatic variable in the code block has been modified by static: Static modified automatic variable, only the storage type has changed, does not affect its scope, can only be accessed within the code. In addition, it persists throughout the execution of the program and will not be reinitialized!

void Count_test () {   static int count = 0;   count++;   printf ("Count is%d\n", count);}

As in the above code, a static variable is built in to count the number of times a function has been called.

Assignment problem for "extended" automatic variable modified by static:

According to the C99 standard: all theexpressions a initializer for a object that have static storage Durationshall be constant expressions O R string Literals. Therefore, it must be only a constant expression or a string constant for assigning a variable that uses the static keyword to change the storage property. Otherwise, a compilation error of "initializer element is not constant" appears.

II Register variable

The keyword register can be used for the declaration of an automatic variable, suggesting that the variable is stored in the register instead of in memory, compared to memory, and the register's variable access effect is better. In general, the most frequently used variables can be present in registers.


Second, string constants:

For string constants, the main focus is on understanding, such as storage location, and some advanced usage. According to the previous storage type, the essence of the string constant is a pointer constant, which should also be stored in the static area.

Char *test_pointer_constant () {    //stack    char detailfaultstr[10] = {0};//locao array is tmp and stored in STACK.
   sprintf (Detailfaultstr, "%s", "ASD");      static data area    char *detailfaultstr = "abc";     return DETAILFAULTSTR;} int main (int argc, char **argv) {    char *tmp = test_pointer_constant ();        printf ("%s.\n", TMP);        return 0;}

The above example from the side reflects that the pointer points to the memory stored in different locations, and different results, the first case is to return an array name, its point of memory exists in the stack, its scope exists only with the entire function, and the second case is to point to the static zone (string constant), Its scope is the entire program run time. In addition to this example, it can be seen that we generally understand that local variables within a function cannot be returned as return values or must be observed in all cases.

The following example shows the flexible use of constant expressions as pointer constants:

void Test_pointer_constant () {    printf ("%s.\n", "xyz"),//xyz    printf ("%s.\n", "xyz" + 1);//yz    printf ("%c.\ N ", *" XYZ "); X    printf ("%c.\n", "XYZ" [1]);//y    printf ("%c.\n", * ("xyz" +2))//z    Putchar ("0123456789ABCDEF" [11%16]) ; can use to convert hexadecimal  //b}




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.