Wednesday, July 9, 2014

What is Typedef

We can define new data-type names using the keyword "typedef".
You are not actually creating a new data-type,rather defining a new name for an existing type.This process can help make machine dependent programs more portable.

General form of the typedef statement is
"typedef "type" Newname;
Ex: typedef float balance;

This statement tells the compiler to recognize the balance as another name for float.Next you could create a float variable using balance.

Ex: balance over_due;

Here over_due is floating point variable of the type balance,which is another word for float.

Static v/s Const variables.

Static variable keep their values and are not destroyed even after they go out of scope.

Eg:
          int ReturnNumber()
          {
               Static int n_id = 0;
               return n_id++;
          }
          int main()
          {
                std::cout<<ReturnNumber();
                std::cout<<ReturnNumber();
                std::cout<<ReturnNumber();
               
                return 0;
          }

Output:    0 1 2.

Const:
         The const keyword specifies that variable's value is constant and tells the compiler to prevent the programmer from modifying it.

 Eg:        const int n = 5;
               n++;          // Error
               n=6;          // Error.
 ----

Wednesday, July 2, 2014

Multi-threading : When to use synchronization classes.

The six Multi-threaded classes provided with MFC fall into two categories.
  1.     Synchronization objects and 
  2.     Synchronization access objects.

1.Synchronization classes are used when access to a resource must be controlled to ensure integrity of the resource.To determine which synchronization class you should use,

  • If the application have to wait for something to happen before it can access the resource use "CEvent".
  • If more than one thread within the same application access this resource at one time use "CSemaphore".
  • Can more than one application use this resource use "CMutex".
  • When a synchronization object that allows one thread at a time to access a resource use "CCriticalSection".
2. Synchronization access classes are used to gain access to these controlled resources.
  • If your application is concerned with accessing a single controlled resource only use "CSingleLock".
  • If your application needs to access to any one of a number of controlled resources use "CMultiLock".


Source:MSDN

String Table

A string table is a Windows resource that contains a list of IDs, values, and captions for all the strings of your application. For exa...