June 18, 2008

DEBUG_NEW

C++ Reference Guide
http://www.cplusplus.com/reference/


What's the functionality of DEBUG_NEW ?

It implements the ability of the debugger to be able to track the line number and file name of where any memory leaks were allocated.
•DEBUG_NEW

Debug release version of the program

You can debug the release version of the program.

In VS2005 you have to do the following changes to project properties dialog for release version.

1.Select "C/C++ ->General" option in "configuration properties", select "Program Database"(/Zi) in the "Debug Information Format" combobox.
2.Select "Link -> Debugging",
select "Yes"(/Debug) in "Generate Debug Info" combobox.

Build your project with this new property settings.
Now you can debug the release version as you debug the release version.

A release version of a program can behave different than the debug version due to optimzier settings. If you find a strange/buggy behavoir disable every optimazion and try again.



ASSERTs will compile to nothing in a release version but VERIFY does. So if you call a function like ASSERT(DoSomething()) this function will not be called in the release version!




June 12, 2008

C++: Some online references

Here are some useful links.

http://www.cplusplus.com/
http://www.cprogramming.com/
http://www.mycplus.com/
http://www.relisoft.com/cpp.html
http://c-faq.com/

C++ Q&A


What are Guard bytes ?
malloc_dbg calls malloc, but requests a few more bytes. These bytes are filled with a predefined value. free_dbg then checks if these extra bytes still hold this value. If they did, you probably wrote beyond the allocated memory (the VC Runtime prints a diagnostic message to the debug output). Typical implementations add 4 bytes at the end.In this case, using free instead of _free_dbg is often not a problem, but depending on the implementation, it might leak the guard bytes. But if an implementation adds guard bytes *before* the memory provided to you (to detect underflows, which are less common), using free instead of -free_dbg is likely to corrupt the heap.



Difference Between WinSock 1.1 and WinSock 2 ?

One of the most important new features is official support for multiple transport protocols. Although Winsock 1.1 was not actually limited to TCP/IP, that was the only protocol that had official support written into the spec. There was no standard way for a vendor to add support for another transport protocol.
Winsock 2 also adds support for technical initiatives like quality of service (QoS) and multicasting. These technologies will become increasingly important as bandwidth requirements become more regimented and intense. For example, QoS allows a videoconferencing program to reserve a certain amount of bandwidth so that a sudden file transfer.
Winsock 2 also allows for "Layered Service Providers." This enables many neat things, such as security plug-ins: drop in, say, an SSL service provider, and all of a sudden your data is automatically encrypted.



What is #Pragmas?
#Pragmas can be used in conditional statements, to provide new preprocessor functionality, or to provide implementation-defined information to the compiler. If the compiler finds a pragmas it does not recognize, it issues a warning, but compilation continues. Some pragmas provide the same functionality as compiler options. When a pragmas is encountered in source code, it overrides the behavior specified by the compiler option.
#pragma once : Used to Compile one time…..Specifies that the file will be included (opened) only once by the compiler when compiling a source code file.



What is Structure Alignment?
Structure Alignment is same as memory padding in structure, add 2 byte for each member for alignment. At the heart of document/view are four key classes:



Q: What are dependent names?
A: Dependent names are names whose definitions are considered to depend upon the template parameters and for which there is no declaration within the template definition. They are resolved only when the template is instantiated. Those that are intended to refer to types or templates may require disambiguation. If the resolution of a dependent function name uses argument-dependent lookup, declarations in the arguments' namespaces that are visible at the point of instantiation will be considered as well as declarations visible at the point of definition. (The former is normally a superset of the latter, but may not be.)


Q: What are non-dependent names?
A: Non-dependent names are those names that are considered not to depend upon the template parameters, plus the name of the template itself and names declared within it (members, friends and local variables). They are resolved when the template is defined, in the normal way, and do not require disambiguation.


Q: Is there a difference between a function template and a template function, or between a class template and a template class?
A: The term "function template" refers to a kind of template. The term "template function" is sometimes used to mean the same thing, and sometimes to mean a function instantiated from a function template. This ambiguity is best avoided by using "function template" for the former and something like "function template instance" or "instance of a function template" for the latter. Note that a function template is not a function. The same distinction applies to "class template" versus "template class".



What is Object Slicing?

Suppose that class D is derived from class C. We can think of D as class C with some extra data and methods. In terms of data, D has all the data that C has, and possible more. In terms of methods, D cannot hide any methods of C, and may have additional methods. In terms of existing methods of C, the only thing that D can do is to override them with its own versions.

If x is an object of class D, then we can slice x with respect to C, by throwing away all of the extensions that made x a D, and keeping only the C part. The result of the slicing is always an object of class C.

What is the difference between GetMessage and PeekMessage?


The major difference between the two is that GetMessage() doesn't return until it finds a message to retrieve from the Application Queue, this allows us to free up precious CPU usage for other programs to use. PeekMessage() returns immediately weather there are any messages or not, this allows us to utilize the time between messages, for example to render a 3D scene.

How to handle command line arguements from simple MFC application ?

Using GetCommandLineArgs() function you can get the arguments in MFC application at any time. In InitInstance () function you can change the behaviour of the application using those values.

June 10, 2008

C++ Programming Tutorials

Check this link
http://www.codersource.net/codersource_cppprogramming.html

It has got explanations with examples.

Our favorite System tools

How can we forget our favorite procexp and tcpview?

Here is where we can get them,
http://technet.microsoft.com/en-us/sysinternals/default.aspx

Open Source software development

Most of us know this site. :-)

http://sourceforge.net/

You can also subscribe to latest news (RSS) on this site to get updates on new and existing projects.

June 9, 2008

Do's N Dont's

As we intend to spread the right knowledge, let us take care of few things.

- Be specific and accurate. Don't post any irrelevant material.
- Do not post mails, snaps, videos etc.
- Ensure that any IP rights or Copyrights are not violated.
- Do not entertain any advertisements or promotions through this site.

Let learning be the ultimate motto.

Welcome to C++ Gyan

Welcome to the world of C++ Gyan.

This is an attempt to put together and share the vast and vivid knowledge of the good old C++ programming language.

The focus will be on sharing of our knowledge on
- FAQs on C/C++.
- Open source implementations/projects.
- C/C++ Interview questions.
- Latest tools and techniques.
etc.

So, go ahead and share the Gyan.