Skip to main content

Posts

Showing posts from July, 2008

Using VSS - Visual Source Safe

VSS : Visual Source Safe The visual source safe should be used to host all the softcopy material of the project. Even though you do not use it as a configuration management tool, it’s use just as a storage device is also very advantageous for the project. Use of VSS allows you to revert back to the older versions of the files easily. Also as every body has it’s code at one place taking the backup becomes very easy. Here are a few points to be remembered when using VSS: 1. From Tools menu options sub menu: In local files tab: Compare files by: Content Replace writable files: Ask Set date/time on local files: Current 2. If the vss is used for storing the files developed on unix platforms, the files are in binary format. ( Refer UseVSSforUnix.doc) Then in Tools->options->File Types Extensions of those files should be w

Clashing for enumerations.

When we use enumerations, by default the values assigned to enumerations start from zero. Suppose you have two classes with classA and classB with enumeraions defined as below. For classA: enum { santro,zen } cars; For classB: enum { Kinetic,sunny} bikes; Now in a function you get some integer which should indicate the type of car or type bike. void findType(int nType) { if( nType == classA::santro ) { cout< } if( nType == classA::zen) { cout< } if( nType == classB::kinetic) { cout< } if( nType == classB::sunny) { cout< } } Now with such a code you will always find out put as santro kinetic OR zen sunny This is because though while coding we use classA::santro and classB::kinetic, both the variables have the same value i.e. zero. Thus for any value of

When to use Switch-case statement

In a situation where, there are a number of conditions to be checked for performing different actions, we tend to use a chain of IF - ELSE IF statements. Such a code looses its readability, making understanding and maintenance difficult. Also if while writing such a code if the braces are not matched properly, some conditions does not produce the required output. But in such a cases if Switch Case statements are used, the code becomes very easy to understand and maintain. Use Switch Case Statements where ever possible instead of IF - ELSE IF statements

Auto Pointer: auto_ptr

Auto Pointer: The C++ standard library contains a class template called auto_ptr, which is just a pointer like object that knows enough to delete what it is pointing to when the pointer goes out of scope. The auto_ptr class takes a pointer to a heap object in its constructor and deletes it in its destructor, freeing the user from responsibility of deleting the pointer. Auto pointers should be used in a function with multiple exit points. So that programmer need not explicitly delete the pointer at multiple places. e.g. In the example below, there are multiple exit points in the function, thus ideal case for using auto pointer. # include # include # include # include vector * getList() { vector<>* pvNumbers = new vector<>; int number; cout<<"give the 5 numbers"; for( int i = 0; i <> { cin>>number; pvNumbers->push_back( number ); } re

Function name mangling for C++ and Java

G++ internals - Mangling Both C++ and Jave provide overloaded function and methods, which are methods with the same types but different parameter lists. Selecting the correct version is done at compile time. Though the overloaded functions have the same name in the source code, they need to be translated into different assembler-level names, since typical assemblers and linkers cannot handle overloading. This process of encoding the parameter types with the method name into a unique name is called name mangling . The inverse process is called demangling . It is convenient that C++ and Java use compatible mangling schemes, since the makes life easier for tools such as gdb, and it eases integration between C++ and Java. Note there is also a standard "Jave Native Interface" (JNI) which implements a different calling convention, and uses a different mangling scheme. The JNI is a rather abstract ABI so Java can call methods written in C or C++; we are concerned he

What is auto_ptr ? Why Call It an "Auto" Pointer?

auto_ptr is just one of a wide array of possible smart pointers. Many commercial libraries provide more sophisticated kinds of smart pointers that can do wild and wonderful things, from managing reference counts to providing advanced proxy services. Think of the Standard C++ auto_ptr as the Ford Escort of smart pointers: A simple general-purpose smart pointer that doesn't have all the gizmos and luxuries of special-purpose or high-performance smart pointers, but that does many common things well and is perfectly suitable for regular daily use. What auto_ptr does is own a dynamically allocated object and perform automatic cleanup when the object is no longer needed. Here's a simple example of code that's unsafe without auto_ptr : // Example 1(a): Original code // void f() { T* pt( new T ); /*...more code...*/ delete pt; } Most of us write code like this every day. If f() is a three-line function that doesn&

Variable Arguments in C-C++ with STDARG Library

Variable Arguments in C/C++ with STDARG Library Introduction The ability to pass a varying number of arguments to a subroutine is a very powerful feature of a programming language. Very few languages support this ability. C and C++ do provide this capability, and they give the programmer a nice level of freedom in how functions can be designed using this capability. In C, two of the most commonly used functions utilize this variable argument capability. The two functions are the standard input/output routines, printf() and scanf() . Below are several examples of using these functions, each example demonstrating that a different number of arguments are passed: printf ("This is a test"); printf ("The result is: %d\n",num); printf ("%d %10.2f %c %-04d %s",num1,f1,chr,num2,str); scanf ("%f",&num); scanf ("%d/%d/%d",&month,&day,&year); Other common languages include the ability for system functions to