Flylib.com

Books Software

 
 
 

_Imaginary

if

The if keyword allows a course of action to be based on the outcome of a condition. The general form of the if statement is

if(

condition

) {

statement block 1

} else {

statement block 2

}

If single statements are used, the braces are not needed. The else is optional.

The condition may be any expression. If that expression evaluates to true (any value other than zero), then statement block 1 will be executed; otherwise , if it exists, statement block 2 will be executed.

The following fragment checks if x is greater than 10:

if(x > 10) cout << "x is greater than 10."; else cout << "x is less than or equal to 10.";


_Imaginary

C99 includes the keyword _Imaginary , which supports complex arithmetic. However, no implementation is required to implement imaginary types and freestanding implementations (those without operating systems) do not have to support complex types. The following _Imaginary types are defined:

float _Imaginary double _Imaginary long double _Imaginary

The reason that _Imaginary , rather than imaginary , was specified as a keyword is that many existing C programs had already defined their own custom imaginary data types using the name imaginary . By using the keyword _Imaginary, C99 avoids breaking this preexisting code.

The header < complex.h > defines (among other things) the macro imaginary , which expands to _Imaginary . Thus, for new C programs, it is best to include < complex.h > and then use the imaginary macro.


inline

The inline specifier tells the compiler to expand a function’s code inline rather than calling the function. The inline specifier is a request, not a command, because several factors may prevent a function’s code from being expanded inline. Some common restrictions include recursive functions, functions that contain loops or switch statements, or functions that contain static data. The inline specifier precedes the rest of a function’s declaration.

The following tells the compiler to generate inline code for myfunc( ) :

inline void myfunc(int i) { // ... }

When a function’s definition is included within a class declaration, that function’s code is automatically inlined, if possible.


int

int is the type specifier used to declare integer variables .


long

long is a data type modifier used to declare long integer or floating-point variables .


mutable

The mutable specifier allows a member of an object to override const ness. That is, a mutable member can be modified by a const member function.


namespace

The namespace keyword allows you to partition the global namespace by creating a declarative region. In essence, a namespace defines a scope. The general form of namespace is shown here:

namespace


name


{ // declarations }

In addition, you can have unnamed namespaces as shown here:

namespace { // declarations }

Unnamed namespaces allow you to establish unique identifiers that are known only within the scope of a single file.

Here is an example of a namespace :

namespace MyNameSpace { int i, k; void myfunc(int j) { cout << j; } }

Here, i , k, and myfunc( ) are part of the scope defined by the MyNameSpac e namespace.

Since a namespace defines a scope, you need to use the scope resolution operator to refer to objects defined within one. For example, to assign the value 10 to i, you must use this statement:

MyNameSpace::i = 10;

If the members of a namespace will be frequently used, the using directive can simplify their access. The using statement has these two general forms:

using namespace

name;

using

name::member;

In the first form, name specifies the name of the namespace you want to access. All of the members defined within the specified namespace can be used without qualification. In the second form, only a specific member of the namespace is made visible. For example, assuming MyNameSpace as shown above, the following using statements and assignments are valid:

using MyNameSpace::k; // only k is made visible k = 10; // OK because k is visible using namespace MyNameSpace; // all members of MyNameSpace are visible i = 10; // OK because all members of MyNameSpace are now visible