RAD Studio |  |

Declaration Syntax
Collapse All

All six interrelated attributes (storage classes, types, scope, visibility, duration, and linkage) are determined in diverse ways by declarations.

Declarations can be defining declarations (also known as definitions) or referencing declarations (sometimes known as nondefining declarations). A defining declaration, as the name implies, performs both the duties of declaring and defining; the nondefining declarations require a definition to be added somewhere in the program. A referencing declaration introduces one or more identifier names into a program. A definition actually allocates memory to an object and associates an identifier with that object.

Topics

Name | Description
Tentative Definitions | The ANSI C standard supports the concept of the tentative definition. Any external data declaration that has no storage class specifier and no initializer is considered a tentative definition. If the identifier declared appears in a later definition, then the tentative definition is treated as if the extern storage class specifier were present. In other words, the tentative definition becomes a simple referencing declaration. If the end of the translation unit is reached and no definition has appeared with an initializer for the identifier, then the tentative definition becomes a full definition, and the object defined has uninitialized (zero-filled) space... more
Possible Declarations | The range of objects that can be declared includes Variables Functions Classes and class members (C++) Types Structure, union, and enumeration tags Structure members Union members Arrays of other types Enumeration constants Statement labels Preprocessor macros The full syntax for declarations is shown in Tables 2.1 through 2.3. The recursive nature of the declarator syntax allows complex declarators. You'll probably want to use typedefs to improve legibility. In CodeGear C++ declaration syntax., note the restrictions on the number and order of modifiers and qualifiers. Also, the modifiers listed are the only addition to the declarator syntax that are... more
External Declarations and Definitions | The storage class specifiers auto and register cannot appear in an external declaration. For each identifier in a translation unit declared with internal linkage, no more than one external definition can be given. An external definition is an external declaration that also defines an object or function; that is, it also allocates storage. If an identifier declared with external linkage is used in an expression (other than as part of the operand of sizeof), then exactly one external definition of that identifier must exist in the entire program. The C++ compiler allows later declarations of external names, such as arrays,... more
Type Specifiers | The type determines how much memory is allocated to an object and how the program interprets the bit patterns found in the object's storage allocation. A data type is the set of values (often implementation-dependent) identifiers can assume, together with the set of operations allowed on those values. The type specifier with one or more optional modifiers is used to specify the type of the declared identifier:
Type Categories | Provides information on C++ type categories. The four basic type categories (and their subcategories) are as follows:
The Fundamental Types | The fundamental type specifiers are built from the following keywords:
Initialization | Initializers set the initial value that is stored in an object (variables, arrays, structures, and so on). If you don't initialize an object, and it has static duration, it will be initialized by default in the following manner: To zero if it is an arithmetic type To null if it is a pointer type Note: If the object has automatic storage duration, its value is indeterminate. Syntax for initializers
Declaration and Declarators | A declaration is a list of names. The names are sometimes referred to as declarators or identifiers. The declaration begins with optional storage class specifiers, type specifiers, and other modifiers. The identifiers are separated by commas and the list is terminated by a semicolon. Simple declarations of variable identifiers have the following pattern:
Use of Storage Class Specifiers | Provides information on C++ storage class specifiers. Storage classes specifiers are also called type specifiers. They dictate the location (data segment, register, heap, or stack) of an object and its duration or lifetime (the entire running time of the program, or during execution of some blocks of code). Storage class can be established by the declaration syntax, by its placement in the source code, or by both of these factors. The keyword mutable does not affect the lifetime of the class member to which it is applied. The storage class specifiers in C++ are: auto __declspec extern mutable register static... more
Variable Modifiers | In addition to the storage class specifier keywords, a declaration can use certain modifiers to alter some aspect of the identifier. The modifiers available are summarized in CodeGear C++ modifiers. The following table summarizes the effects of a modifier applied to a called function. For every modifier, the table shows the order in which the function parameters are pushed on the stack. Next, the table shows whether the calling program (the caller) or the called function (the callee) is responsible for popping the parameters off the stack. Finally, the table shows the effect on the name of a global function.... more
Mixed-Language Calling Conventions | Provides information on C++ mixed-language calling conventions. This section describes C++ mixed-language calling conventions. You can call routines written in other languages, and vice versa. When you mix languages, you have to deal with two important issues: identifiers and parameter passing. By default, the compiler saves all global identifiers in their original case (lower, upper, or mixed) with an underscore "_" prepended to the front of the identifier. To remove the default, you can use the -u command-line option. Note: The section Linkage tells how to use extern , which allows C names to be referenced from a C++ program.... more
Multithread Variables | The following topic describes C++ multithread variables.
Function Modifiers | This section presents descriptions of the function modifiers available with the CodeGear C++ compiler. You can use the __declspec(dllexport), and __declspec(dllimport)and __saveregs modifiers to modify functions. In 32-bit programs the keyword can be applied to class, function, and variable declarations The __declspec(dllexport) modifier makes the function exportable from Windows. The __declspec(dllimport) modifier makes a function available to a Windows program. The keywords are used in an executable (if you don't use smart callbacks) or in a DLL. Functions declared with the __fastcall modifier have different names than their non-__fastcall counterparts. The compiler prefixes the __fastcall function name with... more

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!