TechiWarehouse.Com

Programming Languages


WebReader.CPP - WebReader_cpp C++WebReader.cpp is the file which contains C++ code that will display the code behind a web page. You may copy/paste this follow C++ Code and save it as "WebReader.cpp".
Divider Line

C Programming Tutorial (K/R Ver. 4) -

C Programming TutorialCaution: This tutorial is HUGE. Please allow ample time to load.
Every program is limited by the language which is used to write it. C is a programmer's language. Unlike BASIC or Pascal, C was not written as a teaching aid, but as an implementation language. C is a computer language and a programming tool which has grown popular because programmers like it!

Divider Line

Software Engineering Phases - Software Engineering PhasesThere are four fundamental phases in most, if not all, software engineering methodologies. These phases are analysis, design, implementation, and testing. These phases address what is to be built, how it will be built, building it, and making it high quality. . These steps together define the cradle-to-grave life cycle of the software project. Obviously, if an action is done many times, it needs to be done correctly and efficiently.
Divider Line

Computer Training Excuses - No ExcuseYou wouldn't go to a doctor who had never been to medical school, or hire a lawyer who never studied law. One side-effect of a world advancing as rapidly as ours is that fields are becoming more and more specialized and narrow. People can no longer get by on general knowledge in their careers, something I found out for myself not too long ago. I'd been out of high school for two years, scraping by on my own and picking up scraps of programming as I went. I saw all of the self-taught programmers breaking into the IT industry, and I hoped to do the same. After all, IT is one of the few industries out there where being creative and a quick learner is more important than a degree.
Divider Line

C++ FAQ Lite - C++ FAQ LiteThis is the "BEST" C++ FAQ/Tutorial we've ever come accross. Don't let it slip by. It just has to be read especially by those seeking to get into C++ programming.
Divider Line

Which is the Easiest Programming Language? - Programming LanguagesIf you have some misconception in mind that the programming languages are easy or hard, I am afraid to say that you are mistaken. To tell you frankly about the programming languages, there is nothing such as easy or tough programming language. The only thing that you need to keep in mind while stepping into the world of programming languages is that which programming language would set your base by giving you in-depth knowledge of programming logics and the basics of programming techniques.
Divider Line

Entering into Programming World - Good Luck ProgrammingOnce you have learned some programming languages, you feel yourself completely prepared to enter into the programming world, and start working on the programming languages that you have learned. Many students also feel that they have learned extra things which might be helpful in their programming careers. The matter of fact is that the real world is entirely different from what you have been taught in the classrooms.
Divider Line

Basic Object-Oriented Concepts - Basic Object-Oriented Concepts There is an old story of how several blind men set out to understand what an elephant was by examining a live specimen. Each of them explored a different part of the elephant's body. One blind man, falling against the elephant's side, proclaimed that an elephant must be very much like a wall. Another, grasping the elephant's ear, decided that an elephant must closely resemble a leaf. One grabbed the elephant's tail and determined that elephants must resemble ropes.
Divider Line

Delphi Vs. C Plus Plus : The Problem of Choice - Delphi Vs. C++This article could be useful for those who are going to start programming for Windows platform and doubt with a language to learn. Let's start with the difference: C++ is a programming language when Delphi is a programming environment. For today these are the most common languages for development of high performance Windows-based applications. We do not talk about Visual Basic because its performance is significantly inferior capabilities of both languages.
Divider Line

Why Programmers Love the Night - Programming at night One famous saying says that programmers are machines that turn caffeine from coffee and Coca Cola into a programming code. And if you ask a programmer when does he like working the most and when is he most productive - he is probably going to say late at night or early in the morning, that is when he has the greatest energy and concentration to work.
Divider Line

How to be a Programmer - Programing training To be a good programmer is difficult and noble. The hardest part of making real a collective vision of a software project is dealing with one's coworkers and customers. Writing computer programs is important and takes great intelligence and skill. But it is really child's play compared to everything else that a good programmer must do to make a software system that succeeds for both the customer and myriad colleagues for whom she is partially responsible. In this essay I attempt to summarize as concisely as possible those things that I wish someone had explained to me when I was twenty-one.
Divider Line

TW Tech Glossary - Misplaced your bible? Well here it is - Tech Glosasary! This truly took a while to complete and should be used by all from beginners to advance techies.
Divider Line

How to Install the Aptana Studio IDE on Windows - Aptana Studio 3IDE (Integrated Development Environment) represents an integrated development environment in which you can develop applications. This tutorial will be useful to all those that considering doing programing...
Divider Line

What Programming Language To Learn - Programming LanguagesOne of the most common questions we hear from individuals hoping to enter the IT industry is, "What programming languages do I need to know?" Obviously this is a complex question, and the answer will depend on what field the questioner is going into. Many programming languages are taught during courses used to obtain a computer information science degree. However, those already in IT know that the greatest skill you can have is to be a jack-of-all-trades. A well-prepared worker can switch between computer programming jobs with only minimal training, thanks to a wide knowledge of multiple programming languages.
Divider Line

Ten Commandments for C Programmers - C ProgrammersThese are set of commandments set forth by the God of C. Same set of rules that were revealed on the Mt. ANSI. Learn them well for they shall set you free.
Divider Line

Video Game Proramming as a Career - Video Game Proramming as a Career"My son wants to become a video-game programmer or designer. What advice do you have?" - This is a very common question. Particularly with video games, kids really enjoy playing them, and are often drawn to the potential of creating them as well. There's even a series of TV commercials that play on exactly that scenario. I've hired a lot of programmers in my career. I've also not hired even more. So I definitely have some thoughts and advice.
Divider Line

What is C/C++?

C is a high-level programming language developed by Dennis Ritchie at Bell Labs in the mid 1970s. Although originally designed as a systems programming language , C has proved to be a powerful and flexible language that can be used for a variety of applications, from business programs to engineering. C is a particularly popular language for personal computer because it is relatively small and requires less memory than other languages.

The first major program written in C was the UNIX operating system, and for many years C was considered to be inextricably linked with UNIX.

Although it is a high-level language, C is much closer to assembly language than are most other high-level languages. This closeness to the underlying machine language allows C programmers to write very efficient code.

C++ is an OOP (Object Oriented Programming) in which define not only the data type of a data structure , but also the types of operations that can be applied to the data structure. In this way, the data structure becomes an object that includes both data and functions. In addition, programmers can create relationships between one object and another. For example, objects can inherit characteristics from other objects.

One of the principal advantages of object-oriented programming techniques over procedural programming techniques is that they enable programmers to create modules that do not need to be changed when a new type of object is added. A programmer can simply create a new object that inherits many of its feature from existing objects. This makes object-oriented programs easier to modify.


Tips

IO of binary files

To make sure that there is no CR/LF translation on non-Unix computers, you have to use the following lines to open streams to files with binary data.
 

ofstream os("output.flt", ios::out | ios::binary);
ifstream is("output.flt", ios::in | ios::binary);

For Visual C++, when using fstream.h, use in addition the flag ios::nocreate. Otherwise you can open a non-existing file for reading, without complaining. (This is not necessary when using fstream).

When are destructors called for local variables

Non-static (or 'automatic' ) variables are 'destructed' automatically when they go out of scope. Scope is a fairly complicated thing, and I'm not going to repeat the definition here. Roughly speaking the scope ends when you encounter the } around the declaration of the variable. See also the use of {} and how scope is defined in the for() statement.

Variables are destructed (by the compiler) by calling the appropriate destructor of their class. If the objects allocate memory (and hence the destructor should free that memory), this means that you recover the memory allocated.

class array
{
private:
float *ptr;
public:
// constructor
array(int n) { ptr = new float[n]; }
// destructor
~array() { delete [] ptr; }
}
main()
{
// ...
{
array a(5); // allocates memory
// do something
}
// here the array is destructed, and so the memory is freed
// ...
}

Use {} to keep things local

Use of the grouping construct {} enables you to declare variables local to that group. When leaving the group, all local variables are destructed. This has the advantage that the reader of the code knows (s)he shouldn't worry about these variables to understand the rest of the code.

In a way this can be understood as if every use of {} is like a function call (with local variables declared in the function). Of course, you don't have the overhead of stack manipulations and jumps involved in a proper function call.

// recommended usage
void f(int a)
{
if(a==1)
{
myclassA Aobject;
// here I do something with 'Aobject', and maybe 'b'
}
// Aobject does not exist here anymore
}

This tip is just an extension of the 'avoid global variables' credo.

As always, this can be disabused as in the following piece of code, where the outer variable 'a' is hidden by a local 'a', resulting in not very readable code.

// not very readable code
{
int a=1;
{
// local variable hides outer 'a'
int a;
a = 2;
assert (a==2);
}
// a is again the previous variable
assert (a==1);
}

Scope of variables declared in for()

The new ANSI C++ standard specifies that variables declared as in for(int i=1; ...) have a scope local to the for statement. Unfortunately, older compilers (for instance Visual C++ 5.0) use the older concept that the scope is the enclosing group. Below I list 2 possible problems, and their recommended solutions:

you want to use the variable after the for() statement
you have to declare the variable outside of the for() statement.

 

int i;
for(i=1; i<5; i++)
{ /* do something */ }
if (i==5) ..

 

you want to have multiple for() loops with the same variables.
Put the for statement in its own group. You could also declare the variable outside of the 'for', but it makes it slightly trickier for an optimizing compiler (and a human) to know what you intend.  

{
for(i=1; i<5; i++)
{ /* do something */ }
}

 

.Binding a Reference to an Rvalue

Rvalues and lvalues are a fundamental concept of C++ programming. In essence, an rvalue is an expression that cannot appear on the left-hand side of an assignment expression. By contrast, an lvalue refers to an object (in its wider sense), or a chunk of memory, to which you can write a value. References can be bound to both rvalues and lvalues. However, due to the language's restrictions regarding rvalues, you have to be aware of the restrictions on binding references to rvalues, too. Binding a reference to an rvalue is allowed as long as the reference is bound to a const type. The rationale behind this rule is straightforward: you can't change an rvalue, and only a reference to const ensures that the program doesn't modify an rvalue through its reference. In the following example, the function f() takes a reference to const int:

void f(const int & i);
int main()
{
f(2); /* OK */
}

 The program passes the rvalue 2 as an argument to f(). At runtime, C++ creates a temporary object of type int with the value 2 and binds it to the reference i. The temporary and its reference exist from the moment f() is invoked until it returns; they are destroyed immediately afterwards. Note that had we declared the reference i without the const qualifier, the function f() could have modified its argument, thereby causing undefined behavior. For this reason, you may only bind references to const objects.

struct A{};
void f(const A& a);
int main()
{
f(A()); /* OK, binding a temporary A to a const reference*/
}

Comma-Separated Expressions

Comma-separated expressions were inherited from C. It's likely that you use such expressions in for- and while-loops rather often. Yet, the language rules in this regard are far from being intuitive. First, let's see what a comma separated expression is.

An expression may consist of one or more sub-expressions separated by commas. For example:

if(++x, --y, cin.good()) /*three expressions*/

The if condition contains three expressions separated by commas. C++ ensures that each of the expressions is evaluated and its side effects take place. However, the value of an entire comma-separated expression is only the result of the rightmost expression. Therefore, the if condition above evaluates as true only if cin.good() returns true. Here's another example of a comma expression:

int j=10;
int i=0;
while( ++i, --j)
{
/*..repeat as long as j is not 0*/
}

Calling a Function Before Program's Startup

Certain applications need to invoke startup functions that run before the main program starts. For example, polling, billing, and logger functions must be invoked before the actual program begins. The easiest way to achieve this is by calling these functions from a constructor of a global object. Because global objects are conceptually constructed before the program's outset, these functions will run before main() starts. For example:
 

class Logger
{
public:
Logger()
{
activate_log();
}
};
Logger log; /*global instance*/
int main()
{
record * prec=read_log();
//.. application code
}

The global object log is constructed before main() starts. During its construction, log invokes the function activate_log(). Thus, when main() starts, it can read data from the log file.

Hiding the Cumbersome Syntax of Pointers to Functions

void (*p[10]) (void (*)());

p is an "array of 10 pointers to a function returning void and taking a pointer to another function that returns void and takes no arguments." The cumbersome syntax is nearly indecipherable, isn't it? You can simplify this declaration considerably by using typedefs. First, declare a typedef for "pointer to a function returning void and taking no arguments" as follows:
 

typedef void (*pfv)();

Next, declare another typedef for "pointer to a function returning void and taking a pfv":
 

typedef void (*pf_taking_pfv) (pfv);

Now declaring an array of 10 such pointers is a breeze:
 

pf_taking_pfv p[10]; /*equivalent to
void (*p[10]) (void (*)()); but much more readable*/

All About Pointers to Members

A class can have two general categories of members: function members and data members. Likewise, there are two categories of pointers to members: pointers to member functions and pointers to data members. The latter are less common because in general, classes do not have public data members. However, when using legacy C code that contains structs or classes that happen to have public data members, pointers to data members are useful.

Pointers to members are one of the most intricate syntactic constructs in C++, and yet, they are a very powerful feature too. They enable you to invoke a member function of an object without having to know the name of that function. This is very handy implementing callbacks. Similarly, you can use a pointer to data member to examine and alter the value of a data member without knowing its name.

Avoiding Memory Fragmentation

Often, appl ications that are free from memory leaks but frequently allocate and delocate dynamic memory show gradual performance degradation if they are kept running for long periods. Finally, they crash. Why is this? Recurrent allocation and deallocation of dynamic memory causes heap fragmentation, especially if the application allocates small memory chunks. A fragmented heap might have many free blocks, but these blocks are small and non-contiguous. To demonstrate this, look at the following scheme that represents the system's heap. Zeros indicate free memory blocks and ones indicate memory blocks that are in use: 100101010000101010110

The above heap is highly fragmented. Allocating a memory block that contains five units (i.e., five zeros) will fail, although the systems has 12 free units in total. This is because the free memory isn't contiguous. On the other hand, the following heap has less free memory but it's not fragmented: 1111111111000000

What can you do to avoid heap fragmentation? First, use dynamic memory as little as possible. In most cases, you can use static or automatic storage or use STL containers. Secondly, try to allocate and de-allocate large chunks rather than small ones. For example, instead of allocating a single object, allocate an array of objects at once. As a last resort, use a custom memory pool.

Optimizing Class Member Alignment

The size of a class can be changed simply by playing with the order of its members' declaration:
 

struct A
{
bool a;
int b;
bool c;
}; /*sizeof (A) == 12*/

On my machine, sizeof (A) equals 12. This result might seem surprising because the total size of A's members is only 6 bytes: 1+4+1 bytes. Where did the remaining 6 bytes come from? The compiler inserted 3 padding bytes after each bool member to make it align on a four-byte boundary. You can reduce A's size by reorganizing its data members as follows:  

struct B
{
bool a;
bool c;
int b;
}; // sizeof (B) == 8

This time, the compiler inserted only 2 padding bytes after the member c. Because b occupies four bytes, it naturally aligns on a word boundary without necessitating additional padding bytes.

Eliminating Temporary Objects

C++ creates temporary objects "behind your back" in several contexts. The overhead of a temporary can be significant because both its constructor and destructor are invoked. You can prevent the creation of a temporary object in most cases, though. In the following example, a temporary is created:
 

Complex x, y, z;
x=y+z; /* temporary created */

The expression y+z; results in a temporary object of type Complex that stores the result of the addition. The temporary is then assigned to x and destroyed subsequently. The generation of the temporary object can be avoided in two ways:
 

Complex y,z;
Complex x=y+z; /* initialization instead of assignment */

In the example above, the result of adding x and z is constructed directly into the object x, thereby eliminating the intermediary temporary. Alternatively, you can use += instead of + to get the same effect:
 

/* instead of x = y+z; */
x=y;
x+=z;

Although the += version is less elegant, it costs only two member function calls: assignment operator and operator +=. In contrast, the use of + results in three member function calls: a constructor call for the temporary, a copy constructor call for x, and a destructor call for the temporary.

Storing Dynamically Allocated Objects in STL Containers

Suppose you need to store objects of different types in the same container. Usually, you do this by storing pointers to dynamically allocated objects. However, instead of using named pointers, insert the elements to the container as follows:
 

class Base {};
class Derived : public Base{};
std::vector v;
v.push_back(new Derived);
v.push_back(new Base);
 

This way you ensure that the stored objects can only be accessed through their container. Remember to delete the allocated objects as follows:
 

delete v[0];
delete v[1];

Arguments Into Functions

There are three techniques used to pass variables into a C or C++ functions. ?Pass by value C/C++
?Pass a pointer by value C/C++
?Pass by reference C++ only

Pass by value

The function receives a copy of the variable. This local copy has scope, that is, exists only within the function. Any changes to the variable made in the function are not passed back to the calling routine. The advantages of passing by values are simplicity and that is guaranteed that the variable in the calling routine will be unchanged after return from the function. There are two main disadvantages. First, it is inefficient to make a copy of a variable, particularly if it is large such as an array, structure or class. Second, since the variable in the calling routine will not be modified even if that's what is desired, only way to pass information back to the calling routine is via the return value of the function. Only one value may be passed back this way.

Example:
 

void IncreaseMe(int theInt);
main()
{
int i;
i = 5;
IncreaseMe(i);
cout << "i is %d" << i << " \n";
}

void IncreaseMe(int i)
{
i = i + 1;
}
 

What is printed? Answer: i is 5.
Since i was passed by value, the local copy in the function gets incremented. The copy in main remained unmodified and still will be five.

Passing a pointer by value

A pointer to the variable is passed to the function. The pointer can then be manipulated to change the value of the variable in the calling routine. It is interesting to note that the pointer itself is passed by value. The function cannot change the pointer itself since it gets a local copy of the pointer. However, the function can change the contents of memory, the variable, to which the pointer refers. The advantages of passing by pointer are that any changes to variables will be passed back to the calling routine and that multiple variables can be changed.

Example:
 

void IncreaseMe2(int *theInt);
main()
{
int i;
int *pt;
i = 5;
pt = &i; /* set the pointer to the address of I */
IncreaseMe2(pt);
cout << "i is %d" << i << " \n";
}

void IncreaseMe(int *i)
{
*i = *i + 1;
}
 

What is printed? Answer: i is 6.
Since i was passed by reference, the function received a pointer to the variable. By properly dereferencing, i was incremented to 6. Not that while i was changed, the pointer to i, pt was not.

Passing by reference (C++ only)

C++ provides this third way to pass variables to a function. A reference in C++ is an alias to a variable. Any changes made to the reference will also be made to the original variable. When variables are passed into a function by reference, the modifications made by the function will be seen in the calling routine. References in C++ allow passing by reference like pointers do, but without the complicated notation. Since no local copies of the variables are made in the function, this technique is efficient. Additionally, passing multiple references into the function can modify multiple variables.

Example:
 

void IncreaseMe(int &theInt);
main()
{
int i;
i = 5;
IncreaseMe(i);
cout << "i is %d" << i << " \n";
}

void IncreaseMe(int &i)
{
i = i + 1;
}
 

 

What is printed? Answer: i is 6.
Since I was passed by reference, the variable in the calling routine is modified. Also, note that the main program is identical to the main program in the passing by value example. The compiler does the hard work. The programmer does not need to be concerned with the complicated notation and the explicit referencing and differencing seen when using pointers.

The Use of Braces in C/C++ C and C++ allow two styles of single statement if statements, one with braces and one without.

if (myPocketChange == 1000) {
printf("Do'in Fine");
}
Or alternatively,
if (myPocketChange == 1000)
printf("Do'in Fine");
 

 

Which should you use? Generally, although it involves a little more typing, always use the form with braces. Why? When using nested if statements or the indentation used is misaligned very subtle hard to find bugs can result. Here's how:
 

myEggs = 10;
if (myEggs == 12)
printf("You Have a Dozen");
printf("Prepare the Omelet!!");
strcpy(MyCheese,"CHEDDAR");

Here's the output:

Prepare the Omelet!!

 

Surprised? Before you go on an egg hunt to find the missing two eggs realize that the compiler doesn't care about indentation. Only the first print statement is conditional. The second print statement is not part of the "if" statement. With proper indentation, the same code is:
 

myEggs = 10;
if (myEggs == 12)
printf("You Have a Dozen");
printf("Prepare the Omelet!!");
strcpy(MyCheese,"CHEDDAR");
With braces, it is even clearer.
myEggs = 10;
if (myEggs == 12)
{
printf("You Have a Dozen");
}
printf("Prepare the Omelet!!");
Strcpy(MyCheese,"CHEDDAR");

Show compile duration

Simply add '/Y3' to the command line of VC (In the short cut). You'll now get reports on how long a compile took in your Build window.

Teach VC to intelligently expand classes/structs in debugger

Isn't it neat how VC's debugger knows how to intelligently expand CStrings, CPoints, POINTS, and a lot of other stuff? Well, you can teach it to handle your own structs and classes. Just edit autoexp.dat in sharedide/bin (in the directory where Visual Studio is installed.) The format of that file is fairly complicated, so I suggest just copying the examples already in the file.

Add user defined keywords for syntax highlighting

Why can you set a color for user defined keywords in Tools > Options > Format? Where do you set the keywords? Easy, just create usertype.dat in the sharedide/bin directory that Visual Studio is installed in. Put your keywords in that file, one per line.

How to use .cc file extensions for C++

Make the following modifications to the registry: HKEY_CURRENT_USER\Software\Microsoft\DevStudio\6.0\Text Editor\Tabs/Language Settings\C/C++
FileExtensions=cpp;cxx;c;h;hxx;hpp;inl;tlh;tli;rc;rc2;cc;cp

HKEY_USERS\S-1-5-21-1219703950-274334628-1532313055-1335\Software\Microsoft\DevStudio\6.0\Build System\Components\Platforms\Win32 (x86)\Tools\32-bit C/C++ Compiler for 80x86
Input_Spec=*.c;*.cpp;*.cxx,*Cc,*.cp

HKEY_USERS\S-1-5-21-1219703950-274334628-1532313055-1335\Software\Microsoft\DevStudio\6.0\Build System\Components\Tools\
Input_Spec=*.c;*.cpp;*Cxx;*Cc;*.cp

Add the flag "/Tp" to the compiler settings for the project.

Removing the "docking" capability from the menus

In Tools > Options..., in the Workspace tab, turn on "Use screen reader compatible menus". Your menus will lose the gripper (the double line on the left edge indicating dockability), and will stay nailed down like they should. Unfortunately this also removes the icons from the menus.

Hard code a debugger breakpoint

If you need to insert a hard breakpoint in your code (perhaps because you need to attach to a process), simply add the following line to your code.
 

__asm int 3;

Tracking GDI resource leaks

Plenty of tools exist to help track down memory leaks. You've got the debug heap, Rational Purify for Windows, HeapAgent, and other tools. But there aren't any good tools to help track GDI resource leaks. A resource leak can crash the system under Windows 95 or Windows 98, and can ruin performance on any Windows operating system.

Memory Values

Check this page form information on "Funny" Memory Values. In particular:
If you're using the debug heap, memory is initialized and cleared with special values. Typically MFC automatically adds something like the following to your .cpp files to enable it:
 

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static ch ar THIS_FILE[] = __FILE__;
#endif

You can find information on using the debug heap here. Microsoft defines some of the magic values here. While using the debug heap, you'll see the values: Value Usage
0xCDCDCDCD Allocated in heap, but not initialized
0xDDDDDDDD Released heap memory.
0xFDFDFDFD "NoMansLand" fences automatically placed at boundary of heap memory. Should never be overwritten. If you do overwrite one, you're probably walking off the end of an array.
0xCCCCCCCC Allocated on stack, but not initialized

Display GetLastError's value and message

You can display the value GetLastError() will return by putting "@err" in your watch window. You can see the error message associated with that value by putting "@err,hr" in your watch window. If you've placed an HRESULT in a variable, adding ",hr" to the variable name in the watch window will display the associated text.

Display pointer as an array

If you expand a pointer and you only get a single item, just add ",n" to the entry in the watch window where n is the number of elements to expand. For example, if you have a foo * pFoo pointing to an array of ten elements, put pFoo,10 in your watch window to see all of the element. This can be useful to view parts of a large array. If pFoo points to an array of 5,000 elements, you might use (pFoo + 2000),10 to see elements 2000 through 2009.

Debug checked casts

If you want maximum safety, you should always use dynamic_cast. However, if you feel you must optimize away those costs, use this version of checked_cast. It will ASSERT on a bad cast in Debug builds, but not do the slightly more expensive dynamic_cast in Release builds.
 

// checked_cast - Uses fast static_cast in Release build,
// but checks cast with an ASSERT in Debug.
//
// Typical usage:
// class Foo { /* ... */ };
// class Bar : public Foo { /* ... */ };
// Foo * pFoo = new Bar;
// Bar * pBar = checked_cast(pFoo);
template
TypeTo checked_cast(TypeFrom p)
{
ASSERT(dynamic_cast(p));
return static_cast(p);
}

 

Avoiding Stepping Into Things

It's often useful to avoid stepping into some common code like constructors or overloaded operators. autoexp.dat provides this capability. Add a section called "[ExecutionControl]". Add keys where the key is the function name and the value is "NoStepInto". You can specify an asterisk (*) as a wildcard as the first set of colons for a namespace or class.

autoexp.dat is only read on Visual Studio's start up.

To ignore the function myfunctionname, and all calls to the class CFoo: [ExecutionControl]
myfunctionname=NoStepInto
CFoo::*=NoStepInto

To ignore construction and assignment of MFC CStrings: (Notice the extra = in CString::operator=.) [ExecutionControl]
CString::CString=NoStepInto
CString::operator==NoStepInto To ignore all ATL calls: [ExecutionControl]
ATL::*=NoStepInto  

Naming Threads

Use "SetThreadName". The name is limited to 9 characters. SetThreadName fires an exception, which the debugger will catch and use to name the thread. The name will appears in Debug > Threads dialog.
 

#define MS_VC_EXCEPTION 0x406d1388
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // must be 0x1000
LPCSTR szName; // pointer to name (in same addr space)
DWORD dwThreadID; // thread ID (-1 caller thread)
DWORD dwFlags; // reserved for future use, most be zero
} THREADNAME_INFO;
void SetThreadName(DWORD dwThreadID, LPCTSTR szThreadName)
{
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = szThreadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
__try
{
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(DWORD),
(DWORD *)&info);
}
except (EXCEPTION_CONTINUE_EXECUTION)
{
}
}

 


Did You Know?

  • C and C++ are the two most renowned programming languages in the history of computers. With over 9 million programmer around the world. And this number is expected to double by 2006 since there no need for C++ to go away so soon.

  • The C programming language was devised in the early 1970s as a system implementation language for the nascent Unix operating system.

  • C is generally acknowledged as one of the best programming languages available. It has a rather long story, and has been used for building a lot of the "BIG" programs in existence.




Premium Tutorials & Screencasts



Partners Links
Bjarne Stroustrup's Homepage - Dr. Stroustrup is a University Distinguished Professor and holder of the College of Engineering Chair in Computer Science at Texas A&M University. In his homepage you can find a lot of interesting contents.
Baldwin Programming Tutorials - This web site contains more than 600 programming tutorial lessons about ActionScript, Flex, Alice, Java, JavaScript, Python, XML, C#, etc.
Loirak Development - Loirak is a programming/hobby development site. This site was made to provide an outlet for the information we've found useful, and would like to give back to the community