Tuesday, March 24, 2009

Translation units & Linkage

Translation units
The term translation unit refers to a source code file together with any included files, but less any source lines omitted by conditional preprocessor directives. Syntactically, a translation unit is defined as a sequence of external declarations:

translation-unit:

external-declaration
translation-unit external-declaration
external-declaration
function-definition

declaration

word external has several connotations in C; here it refers to declarations made outside of any function, and which therefore have file scope. (External linkage is a distinct property; see the section
Any declaration that also reserves storage for an object or function is called a definition (or defining declaration).
Linkage
An executable program is usually created by compiling several independent translation units, then linking the resulting object files with preexisting libraries. A problem arises when the same identifier is declared in different scopes (for example, in different files), or declared more than once in the same scope. Linkage is the process that allows each instance of an identifier to be associated correctly with one particular object or function. All identifiers have one of three linkage attributes, closely related to their scope: external linkage, internal linkage, or no linkage. These attributes are determined by the placement and format of your declarations, together with the explicit (or implicit by default) use of the storage class specifier static or extern.

Each instance of a particular identifier with external linkage represents the same object or function throughout the entire set of files and libraries making up the program. Each instance of a particular identifier with internal linkage represents the same object or function within one file only. Identifiers with no linkage represent unique entities.

External and internal linkage rules

Any object or file identifier having file scope will have internal linkage if its declaration contains the storage class specifier static.
For C++, if the same identifier appears with both internal and external linkage within the same file, the identifier will have external linkage. In C, it will have internal linkage.
If the declaration of an object or function identifier contains the storage class specifier extern
, the identifier has the same linkage as any visible declaration of the identifier with file scope. If there is no such visible declaration, the identifier has external linkage.

If a function is declared without a storage class specifier, its linkage is determined as if the storage class specifier extern had been used.
If an object identifier with file scope is declared without a storage class specifier, the identifier has external linkage.

Identifiers with no linkage attribute:

Any identifier declared to be other than an object or a function (for example, a typedef identifier)
Function parameters
Block scope identifiers for objects declared without the storage class specifier extern

Name mangling

When a C++ module is compiled, the compiler generates function names that include an encoding of the function's argument types. This is known as name mangling. It makes overloaded functions possible, and helps the linker catch errors in calls to functions in other modules. However, there are times when you won't want name mangling. When compiling a C++ module to be linked with a module that does not have mangled names, the C++ compiler has to be told not to mangle the names of the functions from the other module. This situation typically arises when linking with libraries or .OBJ files compiled with a C compiler

To tell the C++ compiler not to mangle the name of a function, declare the function as extern "C", like this:

extern "C" void Cfunc( int );

This declaration tells the compiler that references to the function Cfunc should not be mangled.

You can also apply the extern "C" declaration to a block of names:

extern "C" {

void Cfunc1( int );
void Cfunc2( int );
void Cfunc3( int );

};

As with the declaration for a single function, this declaration tells the compiler that references to the functions Cfunc1, Cfunc2, and Cfunc3 should not be mangled. You can also use this form of block declaration when the block of function names is contained in a header file:

extern "C" {

#include "locallib.h"

};

Note: extern “C” cannot be used with class identifiers.

Duration

Duration, closely related to storage class, defines the period during which the declared identifiers have real, physical objects allocated in memory. We also distinguish between compile-time and run-time objects. Variables, for instance, unlike typedefs and types, have real memory allocated during run time. There are three kinds of duration: static, local, and dynamic.

Static

Memory is allocated to objects with static duration as soon as execution is underway; this storage allocation lasts until the program terminates. Static duration objects usually reside in fixed data segments allocated according to the memory model in force, although in 32-bit development, only the flat memory model is supported. All functions, wherever defined, are objects with static duration. All variables with file scope have static duration. Other variables can be given static duration by using the explicit static or extern storage class specifiers.

Static duration objects are initialized to zero (or null) in the absence of any explicit initializer or, in C++, constructor.

Don't confuse static duration with file or global scope. An object can have static duration and local scope

Local

Local duration objects, also known as automatic objects, lead a more precarious existence. They are created on the stack (or in a register) when the enclosing block or function is entered. They are deallocated when the program exits that block or function. Local duration objects must be explicitly initialized; otherwise, their contents are unpredictable. Local duration objects must always have local or function scope. The storage class specifier auto can be used when declaring local duration variables, but is usually redundant, because auto is the default for variables declared within a block. An object with local duration also has local scope, because it does not exist outside of its enclosing block. The converse is not true: a local scope object can have static duration.

When declaring variables (for example, int, char, float), the storage class specifier register also implies auto; but a request (or hint) is passed to the compiler that the object be allocated a register if possible. C++Builder can be set to allocate a register to a local integral or pointer variable, if one is free. If no register is free, the variable is allocated as an auto, local object with no warning or error.

Note: The C++Builder compiler can ignore requests for register allocation. Register allocation is based on the compiler's analysis of how a variable is used.

Dynamic

Dynamic duration objects are created and destroyed by specific function calls during a program. They are allocated storage from a special memory reserve known as the heap, using either standard library functions such as malloc, or by using the C++ operator new. The corresponding deallocations are made using free or delete.
Static
Syntax

static "data definition" ;

static "function name" "function definition" ;

Description

Use the static storage class specifier with a local variable to preserve the last value between successive calls to that function. A static variable acts like a local variable but has the lifetime of an external variable.

In a class, data and member functions can be declared static. Only one copy of the static data exists for all objects of the class.

A static member function of a global class has external linkage. A member of a local class has no linkage. A static member function is associated only with the class in which it is declared. Therefore, such member functions cannot be virtual.

Static member functions can only call other static member functions and only have access to static data. Such member functions do not have a this pointer
Easy SwiftTranslation Units & Linkage

Name spaces & Visibility

Name space is the scope within which an identifier must be unique. C uses four distinct classes of identifiers:
Structure, union, and enumeration tags. These must be unique within the block in which they are defined. Tags declared outside of any function must be unique.
.
goto label names. These must be unique within the function in which they are declared

Variables, typedefs, functions, and enumeration members. These must be unique within the scope in which they are defined. Externally declared identifiers must be unique among externally declared variables.
Structure and union member names. These must be unique within the structure or union in which they are defined. There is no restriction on the type or offset of members with the same member name in different structures

Visibility:
The visibility of an identifier is that region of the program source code from which legal access can be made to the identifier's associated object.

Scope and visibility usually coincide, though there are circumstances under which an object becomes temporarily hidden by the appearance of a duplicate identifier: the object still exists but the original identifier cannot be used to access it until the scope of the duplicate identifier is ended.

Note: Visibility cannot exceed scope, but scope can exceed visibility.

.

.
.
{
int i; char ch; // auto by default
i = 3; // int i and char ch in scope and visible
.
.
.

{
double i;
i = 3.0e3; // double i in scope and visible
// int i=3 in scope but hidden
ch = 'A'; // char ch in scope and visible
}
// double i out of scope
i += 1; // int i visible and = 4
.
.
.
// char ch still in scope & visible = 'A'

}
.
.
.

// int i and char ch out of scope

Again, special rules apply to hidden class names and class member names: C++ operators allow hidden identifiers to be accessed under certain conditions

Storage classes and types

Associating identifiers with objects requires each identifier to have at least two attributes: storage class and type (sometimes referred to as data type). The C++Builder compiler deduces these attributes from implicit or explicit declarations in the source code.

Storage class dictates the location (data segment, register, heap, or stack) of the 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 syntax of the declaration, by its placement in the source code, or by both of these factors.

The type determines how much memory is allocated to an object and how the program will interpret the bit patterns found in the object's storage allocation. A given data type can be viewed as the set of values (often implementation-dependent) that identifiers of that type can assume, together with the set of operations allowed on those values.
The compile-time operator, sizeof, lets you determine the size in bytes of any standard or user-defined type.

Scope
The scope of an identifier is that part of the program in which the identifier can be used to access its object. There are six categories of scope: block (or local), function, function prototype, file, class (C++ only), and namespace (C++ only). These depend on how and where identifiers are declared.

Function.
The only identifiers having function scope are statement labels. Label names can be used with goto statements anywhere in the function in which the label is declared. Labels are declared implicitly by writing label_name: followed by a statement. Label names must be unique within a function.

Block.
The scope of an identifier with block (or local) scope starts at the declaration point and ends at the end of the block containing the declaration (such a block is known as the enclosing block). Parameter declarations with a function definition also have block scope, limited to the scope of the block that defines the function.

Function prototype.
Identifiers declared within the list of parameter declarations in a function prototype (not part of a function definition) have function prototype scope. This scope ends at the end of the function prototype.

File.
File scope identifiers, also known as globals, are declared outside of all blocks and classes; their scope is from the point of declaration to the end of the source file.

Class (C++). A class is a named collection of members, including data structures and functions that act on them. Class scope applies to the names of the members of a particular class.Classes and their objects have many special access and scoping rules;
Condition (C++). Declarations in conditions are supported. Variables can be declared within the expression of if, while, and switch statements. The scope of the variable is that of the statement. In the case of an if statement, the variable is also in scope for the else block.

Move on to Namspacesand Visibility

Language Structure

C++ language and its implementation towards easy swift easy programming C++Builder.

Declarations:
This section briefly reviews concepts related to declarations: objects, storage classes, types, scope, visibility, duration, and linkage. A general knowledge of these is essential before tackling the full declaration syntax. Scope, visibility, duration, and linkage determine those portions of a program that can make legal references to an identifier in order to access its object

Objects:
An object is a specific region of memory that can hold a fixed or variable value (or set of values). (This use of the word object is different from the more general term used in object-oriented languages.) Each value has an associated name and type (also known as a data type). The name is used to access the object. This name can be a simple identifier, or it can be a complex expression that uniquely references the object.
The type is used

to determine the correct memory allocation required initially.
to interpret the bit patterns found in the object during subsequent accesses.
in many type-checking situations, to ensure that illegal assignments are trapped.

C++Builder supports many standard (predefined) and user-defined data types, including signed and unsigned integers in various sizes, floating-point numbers in various precisions, structures, unions, arrays, and classes. In addition, pointers to most of these objects can be established and manipulated in memory.

The C++Builder standard libraries and your own program and header files must provide unambiguous identifiers (or expressions derived from them) and types so that C++Builder can consistently access, interpret, and (possibly) change the bit patterns in memory corresponding to each active object in your program.

Objects and declarations:

Declarations establish the necessary mapping between identifiers and objects. Each declaration associates an identifier with a data type. Most declarations, known as defining declarations, also establish the creation (where and when) of the object; that is, the allocation of physical memory and its possible initialization. Other declarations, known as referencing declarations, simply make their identifiers and types known to the compiler. There can be many referencing declarations for the same identifier, especially in a multifile program, but only one defining declaration for that identifier is allowed.

Generally speaking, an identifier cannot be legally used in a program before its declaration point in the source code. Legal exceptions to this rule (known as forward references) are labels, calls to undeclared functions, and class, struct, or union tags. rvalues

The expression a + b is not an lvalue: a + b = a is illegal because the expression on the left is not related to an object. Such expressions are often called rvalues (short for right values).


lvalues

An lvalue is an object locator: an expression that designates an object. An example of an lvalue expression is *P, where P is any expression evaluating to a non-null pointer. A modifiable lvalue
is an identifier or expression that relates to an object that can be accessed and legally changed in memory. A const pointer to a constant, for example, is not a modifiable lvalue. A pointer to a constant can be changed (but its dereferenced value cannot).

As Featured On EzineArticles
Historically, the l stood for "left," meaning that an lvalue could legally stand on the left (the receiving end) of an assignment statement. Now only modifiable lvalues can legally stand to the left of an assignment statement. For example, if a and b are nonconstant integer identifiers with properly allocated memory storage, they are both modifiable lvalues, and assignments such as a = 1; and b = a + b are legal.
With these fundamentals defimatly progamming will have to be Easy Swift Continue

Monday, March 23, 2009

Home Wave Programming

I have a 2GB DV MP5, MP4 Digital Player. I like the device as it comes with, a camera, player, video and also a webcam USB camera.

The only thing that disturbs me much is I can listen to the radio unless I insert the ear phone to improvise the antenna. Given the radio application, I wonder if it’s possible to program (write a code) in a way that would configure my radio application to receive signals that can be actually be close to an internet connection.As Featured On EzineArticles


In other words, can the radio your listening to or the Aver TV card in your PC receive signals that can be interpreted through a programmed application be harnessed and with the blue tooth technology, establish an internet connection?

We had several ideas of how to easy program and experiment if it were possible but there happened to be draw backs along.

1. The radio waves been received by the media player with the radio receiver were not detected by our Blue tooth device.
2. Owing to the varying between the blue tooth device communicating frequency and the radio waves, there cropped a difficult situation. Communication between devices is very important as we can be able to analyze the waves and set our frequency settings.

We are still looking at this small project. We have no doubt that you might have an idea on how we can easily program more preferably in C++.

Programming gives the ability to see things happen before they are created, let as wait and see.
As Featured On EzineArticles


Swift, EasyBig Programming

Thursday, March 19, 2009

Idea: Phone Programming

Programming has gone up to another level. I was looking at my phone and at one point an idea came up my mind.

How can we program to make things easy and swifter?
I’ve got an idea. New phones are been poured in the market every day.
What if you programmed a phone that could do the following for you?

When you get in a dark room, you don’t have to look for the switch. Reach for the phone in the pocket scroll through your menu, select switch icon and click lights on. This would be very secure as will make a move once the lights are on.

Oh yah I forgot, we parked our car but left the keys inside the car. How can programming save us this time? Lets program the same phone in such a way that I don’t have to go out of the house again to set the car alarm on or break the window to get my keys. Possible. Select menu on your phone, select the related icon car for example and press alarm on. Or the function can be coded in such a way you can memorize the numbers if that’s not to tiresome. Number 1 for lights, Number 2 for stereo play and so on.

This can help prevent young teens from getting your car without your permission. Know how? To enable the alarm or security of the car you have to enter the pin in the phone unlike leaving your keys lying on the table. Yes, that is what I call easy programming. You know this can reduce teens driving without licenses. Meaning that road accidents will also be less. Should we continue programming?

With the easy programming code, the phone can be so small that no one can really believe that you control everything in your house by just using that small programmed phone.
Other possibilities are like enabling door locks, controlling you stereo.
Probably you’ve got something else the phone can do. Programming is the paths to the future so what ever you do continue programming.


As Featured On EzineArticles

Tuesday, March 17, 2009

Programming: Borland C++



The DOS programming application provides a user friendly and easy
to understand programming ground.
The Borland C++ compiler can be configured to wok on any PC. You don’t have to panic that your PC is too old. Start programming with what you have.










Lets Go through an example:
The first input is your library headers example #include. This tells the compiler to check in the library standard input /out put for the functions that were used in your source program. Example is the main() function.
Main() is the beginning of your source file although other source code may come before the main() function. These are mainly function defined by the developer, constants, global variables and many more.
By typing a keyword on the screen, it is possible to get help and examples by placing the cursor below the start of the keyword and then pressing Ctl+F1In the example below the word disk has been type in disk for example as shown on the screen beside.







On pressing Ctl+F1 you get:


























A list of function words with the name disk. Choose the function you wish to use and click on it.








As you can see you are presented with how the function is used and all the variables it can hold.
Try choosing functions that you are familiar with and look at the examples that have been given. Read, Think and Analyze, those are the stream line boosters to swift easy programming.
So next time if someone ask you how to program you will be in a position to hint out what you know.




Thursday, March 12, 2009

Basics

Understand the following so as get a strong structural understanding:
1.Local Variable
2.Global Variables
3.Storage Class Specifiers
4.Extern
5.Static Variables
6.Static Local , Global Variables and Register Variables
7.Assignment Statements
8.Mutiple Assignments
9.Type Conversition
10.Variable Initialization
11.ConstantsOperators
12.Type Converstion
13.Cast
The above are very important
Close Lookat programming basics

Monday, March 9, 2009

Hitting The Road: Start Programming

How to start programming? Yes you can do it in an hour. Get the numerous made simple programming tools under google search.

Tools offer a simpler and more elaborate manner of programming. Why go back to the days of starting from scratch when all the programmers are serving on the new programming made simple tools.

These tools have templates and easy to use interface, that allows you to choose components you want to use in your program. They allow you to directly modify the properties of the components with ease. This cuts down your developing time by nearly 80%.

By saving your templates you can reuse them. How simple.
1Open a made simple programming tool
2. Create a new file
3. Place the components you want to use in your application
4. Change prosperities of the components to suite the way you want them to work
5. Enter your code
6. Use a resource builder to bid your projects to executable Win applications
7. Get market for your applications
What seems to be a scary storm turn out to be a clear sky, sunny day.
So will you give it a try?

Programming is every where. You have it in your mind you only need that breakthrough to put it down and there you go. I want you to see the potential that lies within you and that’s what you need to use.

One other thing you need to have is a source of what you want. I used movies to get me the mood of programming. I used to be amazed by a 15 year boy hacking on behalf of the detective computer guy. Sweet lies. But this really boosted me. What builds your moral? Use it to direct you to get hold of your programming world.

Borland CExample

Thursday, March 5, 2009

Who Can Program Better Than You?

In the old time when people used to program using difficult codes no one ever thought of joining classes as the lessons were similar to counting the sand particles in the Sea.

Now look what is happening in the Markets, in the Industry and even with Private, Businesses.

Any programming language is earning a red carpet welcoming as the demand to design, build and manage the overall activities in the World Market fetches for more simple but more sophisticated applications to satisfy their market needs.
So where have those who are willing to learn the any programming language gone? When I started learning my first programming language I made one terrible mistake.


I showed no Interest in learning how to program and this made my learning more difficult.

Interest is the drive to learning any programming language that you dream to be perfect in.

The secret to program lies in you. You know why?
You might have had a chat on the net and someone happened to tell you that he is good is bringing down PCs, or any one you find in the streets brags how good they are when it comes to programming. But give them a paper and a pen; ask then to write a simple code. What happens? They begin to breathe like furious buffalos. They simply can’t put it down on paper. Why?
These clearly show that there is love for programming but few know how to tap it.


You have to realize that programming is learning a new language all together. The only difference is that the time frame of understanding depends on you. The spirit you put in the learning and the will all depend on how long you will start making the smallest application.
I remember when I was learning, my classmate was more or like born with the programming language in his blood. He fell in love with the technical writing of the language, he would narrate of how he feels relieved when he sits on his desk and builds an application the same way a kid would build a house from light blocks.
That’s the trick! You get bound to the styles, rules, conditions, and the format.

Try it now, give yourself a one week trial and discover what you can do. The power comes out of your finger tips. To lighten your burden let other know what blocks you when it comes to understanding the real "meat" of the language.