Summary of several keywords in C language identifier declaration

Source: Internet
Author: User

CThe declaration of a name in a language is the identification of an identifier with aCassociated with a language object, such as a variable, function, or type,Cthe names that can be declared in a language include: variables, functions, types, type flags, struct members and union members, enumeration constants, statement labels, and preprocessor macros. In addition to the statement labels and preprocessor macros, all identifiers areCa language declaration declares that a variable, function, type is placed in the declarator of the Declaration, the type flag, the struct member and the union member, and the enumeration constant are declared in some type descriptor of the declaration, and the statement designator isCis declared when a language function is present, and the preprocessor macro uses the#definePreprocessor command declarations.

such as the following statement:

extern const volatile unsigned long int i;

It's customary to write the storage class specifier extern constvolatile Span style= "Font-family:wenquanyi Micro Hei" > unsignedlong int

storage class Descriptor determines the lifetime of the declared object (except typedef

auto : only allowed in variable declarations within blocks , which indicates that the variable has a local (automatic) lifetime (this is the default, so c language programs rarely see auto specifier). In a block declaration, the default storage class descriptor is auto

extern : External functions and variable declarations appearing in the top layer or block , which indicates that the declared object has a static lifetime, and the connector knows its name. The default storage class descriptor in the top-level declaration is , but omitting the storage-class specifier differs from providing the extern 。 In a block declaration, if the function, the default storage class specifier is extern

register : can be used for local variables or parameter sounds function equivalent to auto register If there is actual demand, You can add a storage class specifier to a function parameter 。

static : can be placed in function and variable declarations 。 When a function is defined, it is used only to specify the function name without exporting the function to the connector. In a function declaration, it means that a declared function is defined after the file, and the storage class is static Specifies the local lifetime).

typedef : Represents a declaration that defines a new data type name, rather than a function and a variable declaration. The data type name appears where the variable name appears in the variable declaration, and the data type itself is the type to be specified by the variable name.

the function declarator isC99added, function specifierinlinecan only appear in function declarations, which are called inline functions, function specifiers can appear multiple times without changing meanings, usinginlineTipsCimplementation, the function call should be as fast as possible.

The type specifier provides certain information about the data type of the declared program identifier, other type information is specified by the declarator, and the type specifier can also define (as a side effect) type flags, struct member names and union member names, and enumeration constants. Initially,Cthe language allows for omitting variable declarations and type specifiers in function definitions, when the default type descriptor isint, but modernClanguage thinks this is bad programming style, in factC99Treat it as an error, the older compiler does not implementvoidtype, so the purpose of omitting the type specifier in a function definition is to tell the reader that the function does not return a numeric value (but the compiler assumes that it returns a value), modernClanguage is usedvoida type declares a function that has no return value. The type specifier defined by a struct, union, or enumeration defines a new type or enumeration constant, and if you define a type, you can omit all the declarators from the Declaration, write only the type descriptor, and the meaningless declaration is usually ignored.

Type qualifierConst,volatilewith theRestrictspecifies other properties of the type, which are only relevant when accessing the type object through an lvalue. Constwith thevolatileis aC89Increase in theRestrictis aC99added in the.

Const:ConstAn lvalue expression of a qualified type cannot be used to modify an object, that is, the left value cannot be the left operand of an assignment expression or an operand that increments and decrements the operator, in order to use theConstqualifier to specify an object of constant value, allowingCthe language compiler guarantees that the programmer does not change this value. Constwhen used for pointer declaration, the position is different, the effect is different, the following example:

int * Const Const_pointer; Constant pointer const int * POINTER_TO_CONST; Pointers to constant data

volatile : volatile type qualifier tells the standard c language implementation, some objects can be implemented in a way that does not control the value, that is, volatile objects. volatile The most common use is to provide reliable access to special memory addresses. Q, asynchronous processes such as computer hardware or interrupt processors use these special memory addresses.

Restrict:Restrict can only be used to qualify object pointers or incomplete types as CThe non-aliasing hint of the language compiler that only pointers are currently the only way to access the objects they refer to, destroying this hypothesis can result in indeterminate behavior. The advantage of this is that it helps the compiler do better code optimization and generate more efficient assembly code .


Summary of several keywords in C language identifier declaration

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.