<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>techievibes</title>
	<atom:link href="http://techievibes.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://techievibes.com</link>
	<description>C++, VC++, Programming, software tips</description>
	<lastBuildDate>Thu, 25 Mar 2010 08:30:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Show AM/PM For Clock in System Tray (Windows 7)</title>
		<link>http://techievibes.com/?p=455</link>
		<comments>http://techievibes.com/?p=455#comments</comments>
		<pubDate>Thu, 25 Mar 2010 08:26:46 +0000</pubDate>
		<dc:creator>Shibu</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[12 hour format]]></category>
		<category><![CDATA[AM/PM]]></category>
		<category><![CDATA[intl.cpl]]></category>
		<category><![CDATA[show 12 hour format clock in system tray]]></category>
		<category><![CDATA[System clock]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://techievibes.com/?p=455</guid>
		<description><![CDATA[When I started using Windows 7, I felt missing a few features which I used to enjoy in the previous versions of MS Windows. One among them was that I couldn&#8217;t make the system tray clock display the 12 hour format and it continued until I found the following trick.
How to do it

Open Region and [...]]]></description>
			<content:encoded><![CDATA[<p>When I started using <strong>Windows 7</strong>, I felt missing a few features which I used to enjoy in the previous versions of MS Windows. One among them was that I couldn&#8217;t make the system tray clock display the <em>12 hour </em>format and it continued until I found the following trick.</p>
<h3>How to do it</h3>
<ol>
<li>Open <strong>Region and Language settings </strong>in Windows 7 (You can invoke it by the command <strong><em>intl.cpl </em></strong>typed in the <strong>Run </strong>or Start Menu Search box).</li>
<li>Click the button <strong>Additional Settings</strong>.</li>
<li>Go to the <strong>Time </strong>tab.</li>
<li>Change the Long Time format to <strong>HH:mm:ss tt </strong>(That is, append a <strong>tt</strong>).</li>
<li>Now the <strong>AM/PM </strong>will be added to the time in system tray, on pressing <strong>Apply</strong>. However, the time will be still in 24 hour format.</li>
<li>To change it to 12 hour format, change the <strong>HH </strong>to <strong>hh</strong> (That is, hh:mm:ss tt).</li>
</ol>
<p style="text-align: center;"><a href="http://techievibes.com/wp-content/uploads/2010/03/Clock.jpg"><img class="size-medium wp-image-456  aligncenter" title="Clock" src="http://techievibes.com/wp-content/uploads/2010/03/Clock-244x300.jpg" alt="" width="244" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://techievibes.com/?feed=rss2&amp;p=455</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>God Mode In Windows 7</title>
		<link>http://techievibes.com/?p=449</link>
		<comments>http://techievibes.com/?p=449#comments</comments>
		<pubDate>Wed, 24 Mar 2010 07:06:43 +0000</pubDate>
		<dc:creator>Shibu</dc:creator>
				<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[God mode]]></category>
		<category><![CDATA[Godmode in windows 7]]></category>
		<category><![CDATA[Operating systems]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://techievibes.com/?p=449</guid>
		<description><![CDATA[The hidden &#8220;God Mode&#8221; in Windows 7 allows the users to collect the entire controls panels in a single folder. A variety of utilities ranging from modifying mouse pointer to partitioning hard drives and setting up network can be found in a single folder.

How to do it

Make a new folder in Windows 7
Rename it to [...]]]></description>
			<content:encoded><![CDATA[<p>The hidden &#8220;<strong>God Mode</strong>&#8221; in Windows 7 allows the users to collect the entire controls panels in a single folder. A variety of utilities ranging from modifying mouse pointer to partitioning hard drives and setting up network can be found in a single folder.</p>
<p style="text-align: center;"><a href="http://techievibes.com/wp-content/uploads/2010/03/God-mode.jpg"><img class="size-medium wp-image-450  aligncenter" title="God mode" src="http://techievibes.com/wp-content/uploads/2010/03/God-mode-300x168.jpg" alt="" width="386" height="216" /></a></p>
<h2>How to do it</h2>
<ol>
<li>Make a new folder in Windows 7</li>
<li>Rename it to <strong><em>GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}</em></strong></li>
</ol>
<p>The folder will have a name GodMode with the icon of control panel. It is the place you will find all the above utilities.</p>
]]></content:encoded>
			<wfw:commentRss>http://techievibes.com/?feed=rss2&amp;p=449</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Operators which can not be overloaded in C++</title>
		<link>http://techievibes.com/?p=441</link>
		<comments>http://techievibes.com/?p=441#comments</comments>
		<pubDate>Sat, 20 Feb 2010 18:27:21 +0000</pubDate>
		<dc:creator>Shibu</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[operator overloading]]></category>
		<category><![CDATA[Operators which can not be overloaded in C++]]></category>
		<category><![CDATA[Unable to overload operators]]></category>

		<guid isPermaLink="false">http://techievibes.com/?p=441</guid>
		<description><![CDATA[Any operator which operates on value(s) can be overloaded.
For example,


c = a + b;

As the operator + operates on two values, it can be easily overloaded.

Now look at the unary operator *. It operates on the variable name, not on the value.


b = *a;

where a is not a value, but a name.
Similarly the following operators [...]]]></description>
			<content:encoded><![CDATA[<p>Any operator which operates on value(s) can be overloaded.</p>
<p>For example,</p>
<pre class="brush: cpp;">

c = a + b;
</pre>
<p>As the operator<strong> +</strong> operates on two values, it can be easily overloaded.</p>
<p style="text-align: center;"><a href="http://techievibes.com/wp-content/uploads/2010/02/overloaded.jpg"><img class="size-medium wp-image-444 aligncenter" title="overloaded" src="http://techievibes.com/wp-content/uploads/2010/02/overloaded-300x277.jpg" alt="" width="300" height="277" /></a></p>
<p>Now look at the unary operator <strong>*</strong>. It operates on the variable name, not on the value.</p>
<pre class="brush: cpp;">

b = *a;
</pre>
<p>where a is not a value, but a name.</p>
<p>Similarly the following operators can not be overloaded.</p>
<p><strong>sizeof </strong>- The operator to find the size of a variable in memory</p>
<p><strong>? </strong>-The ternary operator</p>
<p><strong>::</strong> &#8211; The scope resolution operator</p>
<p><strong>.</strong> &#8211; The operator to access class members</p>
<p><strong>-&gt;</strong> &#8211; The operator to access class members from a class pointer type variable</p>
<p><strong>*</strong> &#8211; The indirection operator</p>
]]></content:encoded>
			<wfw:commentRss>http://techievibes.com/?feed=rss2&amp;p=441</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Auto Pointers</title>
		<link>http://techievibes.com/?p=430</link>
		<comments>http://techievibes.com/?p=430#comments</comments>
		<pubDate>Sun, 14 Feb 2010 06:15:13 +0000</pubDate>
		<dc:creator>Shibu</dc:creator>
				<category><![CDATA[VC++]]></category>
		<category><![CDATA[auto pointer]]></category>
		<category><![CDATA[automatic garbage collection]]></category>
		<category><![CDATA[automatic pointer]]></category>
		<category><![CDATA[auto_ptr]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[deep copy]]></category>
		<category><![CDATA[shallow copy]]></category>

		<guid isPermaLink="false">http://techievibes.com/?p=430</guid>
		<description><![CDATA[Pointers are still a nightmare for most of the C++ beginners. The confusion where to deallocate, deep copy or shallow copy results in memory leaks and occasional program crashes. A possible remedy to this is auto pointers.

Image courtesy : http://www.usscouts.org

Auto pointers provide some kind of automatic garbage collection. That means the programmer doesn&#8217;t have the [...]]]></description>
			<content:encoded><![CDATA[<p>Pointers are still a nightmare for most of the C++ beginners. The confusion where to deallocate, deep copy or shallow copy results in memory leaks and occasional program crashes. A possible remedy to this is auto pointers.</p>
<p style="text-align: center;"><a href="http://techievibes.com/wp-content/uploads/2010/02/pointer.gif"><img class="aligncenter size-medium wp-image-438" title="pointer" src="http://techievibes.com/wp-content/uploads/2010/02/pointer-217x300.gif" alt="" width="217" height="300" /></a></p>
<pre style="text-align: right;">Image courtesy : http://www.usscouts.org
</pre>
<p>Auto pointers provide some kind of automatic garbage collection. That means the programmer doesn&#8217;t have the headache of deleting the pointer, thereby ensuring that there won&#8217;t be memory leaks due to his carelessness.</p>
<p>Unlike normal pointers, there can be only one owner for an auto pointer at a time, though ownership can be transferred.</p>
<p>An auto pointer can be created using the syntax</p>
<p><strong>auto_ptr&lt;T&gt;<em> variable name</em> (new  T)</strong>, where <em><strong>T</strong></em> is the class type to which the pointer belongs.</p>
<p>An example is</p>
<p><em>auto_ptr&lt;int&gt; myInt(new int(10));</em></p>
<p>To transfer the ownership, we can simply assign the above to another auto_ptr variable.</p>
<p><em>auto_ptr&lt;int&gt; myNewInt = myInt;</em></p>
<p>In this case, myNewInt points to the location where 10 is stored and myInt = NULL:</p>
<p>To assign an auto_ptr to a normal pointer, we can use the auto_ptr method <em>release</em>. Hence, the above functionality can be obtained in the following way also.</p>
<p><em>int* myNormalInt = myInt.release();</em></p>
<p>On calling release, the auto_ptr is set to NULL where as the memory location pointed by it is not destroyed, but assigned to the new variable.</p>
<p>To access the memory location pointed by the <em>auto_ptr</em> variable, we can use the method<em> get()</em>.</p>
<p>A small example is described below.</p>
<p>First we create a simple class</p>
<pre class="brush: cpp;">

// A simple class
class CMyClass
{
public:
   // Constructor
   CMyClass(int no)
   :m_No(no)
   {
   }
   // Display the member variable
   void Display()
   {
      cout &lt;&lt; &quot;No is &lt;&lt; &quot; &lt;&lt; m_No &lt;&lt; &quot;\n&quot;;
   }
private:
   int m_No;
};
</pre>
<p>Now various operations using auto_ptr are shown below.</p>
<pre class="brush: cpp;">

#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &lt;memory&gt;
#include &quot;assert.h&quot;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
   // Create an auto_ptr
   auto_ptr&lt;CMyClass&gt; myClass(new CMyClass(10));
   // Assign the auto pointer to a new auto_ptr
   auto_ptr&lt;CMyClass&gt; myNewClass = myClass;
   // myClass will be NULL now
   assert(myClass.get() == NULL);
   // myNewClass now points to the location
   // where myClass pointed to
   myNewClass-&gt;Display();
   // myNewClass can be assigned to a normal
   // pointer as below
   CMyClass* myNormalClass = myNewClass.release();
   // myNewClass now points to NULL
   assert(myNewClass.get() == NULL);
   // myNormalClass now points to the location
   // myNewClass pointed to
   myNormalClass-&gt;Display();
   // Finally, we can delete myNormalClass.
   // Note that the auto_ptr variables do
   // not need deletion
   delete myNormalClass;
   myNormalClass = NULL;
   return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://techievibes.com/?feed=rss2&amp;p=430</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cppkid has a new home</title>
		<link>http://techievibes.com/?p=416</link>
		<comments>http://techievibes.com/?p=416#comments</comments>
		<pubDate>Sat, 13 Feb 2010 11:06:18 +0000</pubDate>
		<dc:creator>Shibu</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://techievibes.com/?p=416</guid>
		<description><![CDATA[
Image courtesy : http://www.freeprintablecoloringpages.net
A couple of years ago, cppkid stepped into the world of technical blogging with free space provided generously by Wordpress with an idea to share what he was learning. He has now got his own home in the cyber world under the name techievibes.
He is always grateful to the support he has [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://techievibes.com/wp-content/uploads/2010/02/Home.jpg"><img class="size-full wp-image-417 aligncenter" title="Home" src="http://techievibes.com/wp-content/uploads/2010/02/Home.jpg" alt="" width="300" height="297" /></a></p>
<pre style="text-align: right;">Image courtesy : http://www.freeprintablecoloringpages.net</pre>
<p style="text-align: justify;">A couple of years ago, <a title="Cppkid" href="http://cppkid.wordpress.com" target="_blank">cppkid </a>stepped into the world of technical blogging with free space provided generously by <a href="http://www.wordpress.com" target="_blank">Wordpress</a> with an idea to share what he was learning. He has now got his own home in the cyber world under the name <a title="techievibes - sharing technology" href="http://techievibes.com">techievibes</a>.</p>
<p style="text-align: justify;">He is always grateful to the support he has got and he hopes that it will continue in the future also. He once again expresses his sincere thanks to all who have provided support (through both criticism and praise).</p>
<p style="text-align: justify;">See you with next post soon&#8230;..</p>
]]></content:encoded>
			<wfw:commentRss>http://techievibes.com/?feed=rss2&amp;p=416</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Round Off A Number</title>
		<link>http://techievibes.com/?p=302</link>
		<comments>http://techievibes.com/?p=302#comments</comments>
		<pubDate>Wed, 18 Feb 2009 12:06:09 +0000</pubDate>
		<dc:creator>Shibu</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[how to round a float]]></category>
		<category><![CDATA[remove decimals from a number]]></category>
		<category><![CDATA[Round a number]]></category>
		<category><![CDATA[round decimal places]]></category>
		<category><![CDATA[round off float]]></category>
		<category><![CDATA[round off number]]></category>

		<guid isPermaLink="false">http://cppkid.wordpress.com/?p=302</guid>
		<description><![CDATA[Sometimes, it is needed to round off a number to some decimal digits.  Again stringstream comes to help us with the aid of iomanip function setprecision. Following is a sample function to round off a number to a fixed digits.

double Round(const double value, const int digits)
{
   stringstream stream;
   // Store the [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, it is needed to round off a number to some decimal digits.  Again <strong>stringstream </strong>comes to help us with the aid of <strong>iomanip</strong> function <strong>setprecision</strong>. Following is a sample function to round off a number to a fixed digits.</p>
<pre class="brush: cpp;">
double Round(const double value, const int digits)
{
   stringstream stream;
   // Store the number with required no. of decimal
   // places to stream
   stream &lt;&lt; setprecision(digits) &lt;&lt; value;
   // Convert stream to number
   double roundedValue = 0.0;
   stream &gt;&gt; roundedValue;
   return roundedValue;
}
</pre>
<p>The header files <strong>sstream </strong>and <strong>iomanip </strong>are needed for the above.</p>
<p>Please note that the variable value holds the <em>number with original no. of decimal places</em> and <em>digits is the total number of digits needed (including the non-decimal digits) after rounding has taken place</em>.</p>
<p><strong>Round(10.37665, 3)</strong> gives <strong>10.4</strong> and <strong>Round(10.3745, 4)</strong> gives <strong>10.37</strong>.</p>
<h2>Note</h2>
<p>If you want to store the number in scientific notation in stream, you can do</p>
<p><em>stream &lt;&lt;  scientific;</em></p>
<p>For fixed point format, do</p>
<p><em>stream &lt;&lt;  fixed;</em></p>
]]></content:encoded>
			<wfw:commentRss>http://techievibes.com/?feed=rss2&amp;p=302</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How To Set Extra Data With Each Row Of A List Box</title>
		<link>http://techievibes.com/?p=296</link>
		<comments>http://techievibes.com/?p=296#comments</comments>
		<pubDate>Tue, 03 Feb 2009 11:23:38 +0000</pubDate>
		<dc:creator>Shibu</dc:creator>
				<category><![CDATA[VC++]]></category>
		<category><![CDATA[adding extra data to CListBox]]></category>
		<category><![CDATA[get data from list box]]></category>
		<category><![CDATA[GetItemData]]></category>
		<category><![CDATA[List box]]></category>
		<category><![CDATA[set data to list box]]></category>
		<category><![CDATA[Set extra data with each row of list box]]></category>
		<category><![CDATA[SetItemData]]></category>
		<category><![CDATA[Store information in CListBox row]]></category>

		<guid isPermaLink="false">http://cppkid.wordpress.com/?p=296</guid>
		<description><![CDATA[We can associate a 32 bit value with each row of a list box. The member function SetItemData() of CListBox can be used for this purpose.
The syntax is

int SetItemData(
   int nIndex,
   DWORD_PTR dwItemData
);

Parameters

nIndex &#8211; Zero based row index of the list box
dwItemData &#8211; 32 bit value to be stored in the [...]]]></description>
			<content:encoded><![CDATA[<p>We can associate a <strong>32 bit value</strong> with each row of a list box. The member function <strong>SetItemData()</strong> of <strong>CListBox </strong>can be used for this purpose.</p>
<p>The syntax is</p>
<pre class="brush: cpp;">
int SetItemData(
   int nIndex,
   DWORD_PTR dwItemData
);
</pre>
<h4>Parameters</h4>
<ul>
<li>nIndex &#8211; Zero based row index of the list box</li>
<li>dwItemData &#8211; 32 bit value to be stored in the row</li>
</ul>
<p>The return value will be <strong>LB_ERR</strong>, if an error occurs.<br />
The stored value can be retrieved using <strong>CListBox::GetItemData()</strong>. Again, the syntax is</p>
<pre class="libCScode" style="white-space: pre-wrap;">
<pre class="brush: cpp;">
DWORD_PTR GetItemData(
   int nIndex
) const;
</pre>
<p>where nIndex is the zero based index of the list box row, from where we have to get the data.</p>
<p>An example is given below.</p>
<pre class="brush: cpp;">
for (int index = 0; index &lt; myListBox-&gt;GetCount(); ++index)
{
   if (myListBox-&gt;GetItemData(index) == DWORD(-1))
   {
      myListBox-&gt;SetItemData(index, 0);
   }
}
</pre>
<p>The header file <strong>afxwin.h</strong> is needed for the above functions.</pre>
]]></content:encoded>
			<wfw:commentRss>http://techievibes.com/?feed=rss2&amp;p=296</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Issue When Using [] Operator To Access Elements Of A map</title>
		<link>http://techievibes.com/?p=285</link>
		<comments>http://techievibes.com/?p=285#comments</comments>
		<pubDate>Thu, 29 Jan 2009 17:54:34 +0000</pubDate>
		<dc:creator>Shibu</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[access element of a map]]></category>
		<category><![CDATA[get element of a map]]></category>
		<category><![CDATA[map in C++]]></category>
		<category><![CDATA[map issue]]></category>
		<category><![CDATA[problem with map]]></category>
		<category><![CDATA[stl map]]></category>
		<category><![CDATA[[] for map]]></category>

		<guid isPermaLink="false">http://cppkid.wordpress.com/?p=285</guid>
		<description><![CDATA[I had the habit of using [] operator to access elements of a map. For example, if we have
map&#60;int, int&#62; myMap, to get the element corresponding to 10, we can use
myMap[10]. This is perfectly ok as long as we have an element corresponding to 10. But, what if we don&#8217;t have one corresponding to 10?
There [...]]]></description>
			<content:encoded><![CDATA[<p>I had the habit of using<strong> []</strong> operator to access elements of a map. For example, if we have</p>
<p><strong>map&lt;int, int&gt; myMap</strong>, to get the element corresponding to <strong>10</strong>, we can use</p>
<p><strong>myMap[10]</strong>. This is perfectly ok as long as we have an element corresponding to <strong>10</strong>. But, w<em>hat if we don&#8217;t have one corresponding to 10?</em></p>
<p>There lies the problem. In this situation, <strong>myMap </strong>is already added with a default elemnent corresponding to <strong>10 </strong>(<em>[</em><em>] operator provides no facility to validate if an element exists</em>) and in the above situation, it is <strong>0</strong>. As a result, a new (unwanted) element is added to the map (<em>we can see that the size of map has been incremented by 1</em>).</p>
<p>So a better alternative is to use the <strong>find()</strong> function associated with <strong>map</strong>. It does not add an element and if the element is not found, it will return <strong>map::end()</strong>.</p>
<p>The example given below illustrates this.</p>
<pre class="brush: cpp;">
#include &lt;map&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
   map myMap;
   cout &lt;&lt; &quot;Size of myMap = &quot; &lt;&lt; myMap.size() &lt;&lt; '\n';   // will be 0
   int content = myMap[0];
   // Now the size of myMap will be 1 as we used the [] operator
   // and the value of content = myMap[0] = 0
   cout &lt;&lt; &quot;Size of myMap = &quot; &lt;&lt; myMap.size() &lt;&lt; '\n';   
   // Instead, if we use find, the size will not change.
   // It will look for the element only.
   map::const_iterator it = myMap.find(1);
   // Here the element has not been found. So it = myMap.end()
   cout &lt;&lt; &quot;Size of myMap = &quot; &lt;&lt; myMap.size() &lt;&lt; '\n';   // will be 1 only 
   return 0;   
}
</pre>
<p>So the best practice is to avoid [] operator for accessing individual elements of a map.</p>
]]></content:encoded>
			<wfw:commentRss>http://techievibes.com/?feed=rss2&amp;p=285</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>How To Watch A Variable Even After Its Scope Is Over</title>
		<link>http://techievibes.com/?p=263</link>
		<comments>http://techievibes.com/?p=263#comments</comments>
		<pubDate>Mon, 19 Jan 2009 18:34:23 +0000</pubDate>
		<dc:creator>Shibu</dc:creator>
				<category><![CDATA[VC++]]></category>
		<category><![CDATA[how to watch a variable]]></category>
		<category><![CDATA[Watch a variable]]></category>
		<category><![CDATA[watch a variable after its scope is over]]></category>
		<category><![CDATA[watch a variable througout the program]]></category>
		<category><![CDATA[watch window]]></category>

		<guid isPermaLink="false">http://cppkid.wordpress.com/?p=263</guid>
		<description><![CDATA[Noramally, the value of a variable declared in a function can be seen in the watch window only when the control is inside that function itself (eg. When the above function calles a new function and if we step into the new function.) . Let&#8217;s discuss an example.

void SomeFunction()
{
   int myVariable = 20;
}
int main()
{
   int [...]]]></description>
			<content:encoded><![CDATA[<p>Noramally, the value of a variable declared in a function can be seen in the watch window only when the control is inside that function itself (eg. When the above function calles a new function and if we step into the new function.) . Let&#8217;s discuss an example.</p>
<pre class="brush: cpp;">
void SomeFunction()
{
   int myVariable = 20;
}
int main()
{
   int myVariable = 10;
   SomeFunction();
   return 0;   
}
</pre>
<p>In the above example, if I put a break point in the function main after the statement <strong>int myVariable = 10;</strong> I can see the value of myVariable in the watch window as follows.</p>
<p style="text-align:center;"><a href="http://cppkid.files.wordpress.com/2009/01/break-point-in-main4.jpg"><img class="alignnone size-full wp-image-277" title="break-point-in-main4" src="http://cppkid.files.wordpress.com/2009/01/break-point-in-main4.jpg" alt="break-point-in-main4" width="450" height="281" /></a></p>
<p>Now, if I put another break point in <strong>SomeFunction()</strong> after the statement <strong>int myVariable = 20;</strong>, when th execution flow reaches there, the watch window will show the value of myariable as <strong>20</strong> only.</p>
<p>So we have lost the value of <strong>myVariable</strong> declared in <strong>main()</strong>, eventhogh it lifetime is not over now.</p>
<h3>How To Add a Permanent watch</h3>
<p>We can still view the value of myVariable declared in <strong>main(</strong>) inside the function S<strong>omeFunction()</strong>. For this, we will use the <strong>address</strong> of memory location (rather than the variable name) in which <strong>myVariable</strong> has been declared in <strong>main()</strong>. We can view the contents of this memory location as long as it has life in the program.</p>
<p>When the control reaches the break point in <strong>main()</strong>, take the address of <strong>myVariable</strong> using the <strong>&amp;</strong> operator. Now we have a valid memory location address (a pointer). Still, it can be a raw pointer. So cast it to the correct type (int, in this case, as <strong>myVariable</strong> is of type integer) as</p>
<p><em>(int*)(address of myVariable)</em></p>
<p style="text-align:center;"><a href="http://cppkid.files.wordpress.com/2009/01/adding-a-watch.jpg"></a></p>
<p><a href="http://cppkid.files.wordpress.com/2009/01/adding-a-watch1.jpg"><img class="aligncenter size-full wp-image-281" title="adding-a-watch1" src="http://cppkid.files.wordpress.com/2009/01/adding-a-watch1.jpg" alt="adding-a-watch1" width="450" height="281" /></a>Now see how the watch window shows the value we have stored, when the control reaches the second break point.</p>
<p style="text-align:center;"><a href="http://cppkid.files.wordpress.com/2009/01/watching-the-old-variable1.jpg"><img class="aligncenter size-full wp-image-282" title="watching-the-old-variable1" src="http://cppkid.files.wordpress.com/2009/01/watching-the-old-variable1.jpg" alt="watching-the-old-variable1" width="450" height="281" /></a><a href="http://cppkid.files.wordpress.com/2009/01/watching-the-old-variable.jpg"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://techievibes.com/?feed=rss2&amp;p=263</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How To Handle new Operator Failure</title>
		<link>http://techievibes.com/?p=255</link>
		<comments>http://techievibes.com/?p=255#comments</comments>
		<pubDate>Thu, 15 Jan 2009 05:46:35 +0000</pubDate>
		<dc:creator>Shibu</dc:creator>
				<category><![CDATA[VC++]]></category>
		<category><![CDATA[bad_alloc]]></category>
		<category><![CDATA[handle memory allocation failure]]></category>
		<category><![CDATA[new]]></category>
		<category><![CDATA[new fails]]></category>
		<category><![CDATA[operator new]]></category>

		<guid isPermaLink="false">http://cppkid.wordpress.com/?p=255</guid>
		<description><![CDATA[new operator is used to allocate memory in C++. Though it is rare that a modern day computer is not able to allocate memory for our program, still there may be situations where we have to face situations where the new operator fails. The function set_new_handler will divert the flow to a user function when the [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>new</em></strong> operator is used to allocate memory in C++. Though it is rare that a modern day computer is not able to allocate memory for our program, still there may be situations where we have to face situations where the new operator fails. The function <strong>set_new_handler</strong> will divert the flow to a user function when the new operator fails. A simple example is given below.</p>
<pre class="brush: cpp;">
#include &lt;iostream&gt;
using namespace std;

// Function to be called when the new operator fails
void NewHandler()
{
   cout &lt;&lt; &quot;Out of memory&quot; &lt;&lt; '\n';
   exit(0);
}
 
int main()
{
   // Set the function to be called when new operator fails
   set_new_handler(NewHandler);
   while (true)
   {
      new int[50000000];   // Hope this will fail after a few iterations
      cout &lt;&lt; &quot;Successful so far&quot; &lt;&lt; '\n';
   }
   return 0;
}
</pre>
<p>In the above example, the function NewHandler() will be called when the memory allocation using new operator fails.</p>
<h3><strong>Some Background Info</strong></h3>
<p><strong>set_new_handle</strong>r will store the function <strong>NewHandler()</strong> in a static <a href="http://msdn.microsoft.com/en-us/library/we2zys4d(VS.80).aspx" target="_blank">new handler</a> pointer. This new handler is used by operator <em><strong>new</strong></em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://techievibes.com/?feed=rss2&amp;p=255</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
