<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Some C++ Gotchas</title><link>http://blogs.msdn.com/b/vcblog/archive/2008/06/05/some-c-gotchas.aspx</link><description>Hi - Jonathan Caves again. Over the last couple of weeks I’ve seen some reports from users that the C++ compiler does not act the way they think it should. As it turns these reports weren’t real bugs, but the issues brought up are interesting enough to</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>2009 Q1 link clearance: Microsoft blogger edition</title><link>http://blogs.msdn.com/b/vcblog/archive/2008/06/05/some-c-gotchas.aspx#9523308</link><pubDate>Tue, 31 Mar 2009 19:55:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9523308</guid><dc:creator>The Old New Thing</dc:creator><description>&lt;p&gt;From elsewhere in the collective.&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9523308" width="1" height="1"&gt;</description></item><item><title>TR1 Fixes In VC9 SP1</title><link>http://blogs.msdn.com/b/vcblog/archive/2008/06/05/some-c-gotchas.aspx#8848944</link><pubDate>Mon, 11 Aug 2008 22:37:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8848944</guid><dc:creator>Visual C++ Team Blog</dc:creator><description>&lt;p&gt;STL enjoys speaking in the third person and also enjoys bringing you this exclusive news: Visual Studio&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8848944" width="1" height="1"&gt;</description></item><item><title>re: Some C++ Gotchas</title><link>http://blogs.msdn.com/b/vcblog/archive/2008/06/05/some-c-gotchas.aspx#8669272</link><pubDate>Mon, 30 Jun 2008 03:41:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8669272</guid><dc:creator>Norman Diamond</dc:creator><description>&lt;p&gt;Betas are betas. &amp;nbsp;Now if betas were betas for a reason, so that bugs found in betas would not be present in releases, then betas would be really valuable. &amp;nbsp;But betas would still be betas. &amp;nbsp;You should know to download and install betas on machines that are dedicated to experimenting.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8669272" width="1" height="1"&gt;</description></item><item><title>re: Some C++ Gotchas</title><link>http://blogs.msdn.com/b/vcblog/archive/2008/06/05/some-c-gotchas.aspx#8666887</link><pubDate>Sun, 29 Jun 2008 12:49:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8666887</guid><dc:creator>Khris</dc:creator><description>&lt;p&gt;I recommend that you do not download this beta. It totally damaged my SQL server and Framework up to the point that I cannot unistall and reinstall. It causes system problems. Its a real pain in my ass because I've tried everything to fix it and I've only attained partial progresss. I won't download a beta like this. I've heard rumors that Vista and new programs have problems but I didn't think I'd ever really have a problem because I know how to fix most problems but this is annoying. My system did not crash but everytime I start up it tells me that SQL is incomplete or corrupt. I like no problems but I guess I'm going to have to live with this one unless I reinstall all my programs which I don't want to do. frustration.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8666887" width="1" height="1"&gt;</description></item><item><title>re: Some C++ Gotchas</title><link>http://blogs.msdn.com/b/vcblog/archive/2008/06/05/some-c-gotchas.aspx#8641480</link><pubDate>Mon, 23 Jun 2008 09:50:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8641480</guid><dc:creator>Norman Diamond</dc:creator><description>&lt;p&gt;&amp;quot;In C and C++, pointers are considered signed for the purposes of casting.&amp;quot;&lt;/p&gt;
&lt;p&gt;In the old days, before the &amp;quot;unsigned&amp;quot; keyword was invented, C hackers knew how to get one. &amp;nbsp;On the PDP-11, &amp;quot;int&amp;quot; was signed 16 bits, and &amp;quot;char*&amp;quot; was unsigned 16 bits.&lt;/p&gt;
&lt;p&gt;Now fast-forward to some popular implementations on modern hardware...&lt;/p&gt;
&lt;p&gt;&amp;quot;(intptr_t) 0x80000000&amp;quot;&lt;/p&gt;
&lt;p&gt;The result of the cast to intptr_t is signed because intptr_t is a signed type. &amp;nbsp;If intptr_t is 64 bits then I think the semantics are value preserving, signed value 0x0000000080000000. &amp;nbsp;If intptr_t is 32 bits then you get a signed result after the overflow.&lt;/p&gt;
&lt;p&gt;&amp;quot;(long long) &amp;amp;var&amp;quot;&lt;/p&gt;
&lt;p&gt;If the pointer is 32 bits then I think the semantics are value preserving. &amp;nbsp;I think your example demonstrated that the pointer representation is treated as an unsigned representation before being converted.&lt;/p&gt;
&lt;p&gt;I see why you want a warning when a pointer type is cast to a signed type, but I wonder if it would be more suitable in Prefast tests than built into the DDK's compiler. &amp;nbsp;Do you also want a warning when an unsigned int constant is cast to a signed type, to catch your first example too? &amp;nbsp;Maybe you should suggest these to the Prefast team?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8641480" width="1" height="1"&gt;</description></item><item><title>re: Some C++ Gotchas</title><link>http://blogs.msdn.com/b/vcblog/archive/2008/06/05/some-c-gotchas.aspx#8640921</link><pubDate>Mon, 23 Jun 2008 05:44:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8640921</guid><dc:creator>Myria</dc:creator><description>&lt;p&gt;In my ~10 years of using Visual Studio, I've only encountered one previously unknown compiler bug. &amp;nbsp;It was a ridiculously obscure bug involving rare compilation conditions.&lt;/p&gt;
&lt;p&gt;In C and C++, pointers are considered signed for the purposes of casting. &amp;nbsp;This means that if you cast a pointer to an integer type of size larger than a pointer, sign extension is used. &amp;nbsp;This can occur with 32-bit compilation, and indeed works in this context:&lt;/p&gt;
&lt;p&gt;int wmain()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp;void* ptr = (void*) (intptr_t) 0x80000000;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;wprintf(L&amp;quot;%016llX&amp;quot;, (long long) ptr);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;This will print FFFFFFFF80000000 due to the sign extension, and is the expected answer.&lt;/p&gt;
&lt;p&gt;However, if the value is a compile-time constant referring to the address of a global object or function, the compiler can zero-extend. &amp;nbsp;This happens if the global object's address is larger than 7FFFFFFF on a 32-bit target:&lt;/p&gt;
&lt;p&gt;int var;&lt;/p&gt;
&lt;p&gt;long long address = (long long) &amp;amp;var;&lt;/p&gt;
&lt;p&gt;If the base address of the DLL has its high bit set, the compiler will emit a zero-extended address of var. &amp;nbsp;This can only occur when compiling Windows NT kernel drivers.&lt;/p&gt;
&lt;p&gt;The compiler or linker should actually error or warn instead of allowing this. &amp;nbsp;It is not possible in the 32-bit Portable Executable format to emit this type of relocation (sign-extend relocated address). &amp;nbsp;However, this case is so obscure that it was deemed unworthy of being fixed.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8640921" width="1" height="1"&gt;</description></item><item><title>re: Some C++ Gotchas</title><link>http://blogs.msdn.com/b/vcblog/archive/2008/06/05/some-c-gotchas.aspx#8639025</link><pubDate>Sun, 22 Jun 2008 18:21:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8639025</guid><dc:creator>Christian Gross</dc:creator><description>&lt;p&gt;To David Roe&lt;/p&gt;
&lt;p&gt;I stumbled on this blog by accident (was searching something else). But I USED stress USED to be a C++ programmer. When I see blog entries like these I think, &amp;quot;gee I am glad I switched programming languages.&amp;quot;&lt;/p&gt;
&lt;p&gt;When I need to switch to low level, believe it or not I use C! I find C a whole lot more comforting and straight forward... And with this functional drive coming implementing functional constructs in C is DEAD SIMPLE...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8639025" width="1" height="1"&gt;</description></item><item><title>Intellisense</title><link>http://blogs.msdn.com/b/vcblog/archive/2008/06/05/some-c-gotchas.aspx#8637956</link><pubDate>Sun, 22 Jun 2008 13:41:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8637956</guid><dc:creator>Norman Diamond</dc:creator><description>&lt;p&gt;The MSDN forums are still giving ASP error 500 every time I try to log in and/or post. &amp;nbsp;I see other people have posted but I can't guess how they do it. &amp;nbsp;I'm using IE6 in Windows XP SP3, but the errors aren't in IE, they're server error 500's in Microsoft.&lt;/p&gt;
&lt;p&gt;Therefore I resort to posting here again.&lt;/p&gt;
&lt;p&gt;This time the problem isn't user error. &amp;nbsp;Intellisense is still the same in VC++2008 RTM as it was in VC++2005 betas.&lt;/p&gt;
&lt;p&gt; I close Visual Studio 2008, delete the .ncb file, double-click the .sln file again, wait for Visual Studio 2008 to rebuild broken Intellisense information, and it is rebuilt broken.&lt;/p&gt;
&lt;p&gt;If I hover the mouse cursor over an identifier, a tooltip might or might not display. &amp;nbsp;Today the failure occurs most often if the identifier is a member of a derived class.&lt;/p&gt;
&lt;p&gt;If I type code like&lt;/p&gt;
&lt;p&gt;this-&amp;gt;&lt;/p&gt;
&lt;p&gt;there is an error that the left hand operator of -&amp;gt; is invalid. &amp;nbsp;It compiles correctly, but the bug isn't in the compiler, the bug is in Intellisense.&lt;/p&gt;
&lt;p&gt;If I type a member function name correctly and then a left parenthesis, no tooltip appears.&lt;/p&gt;
&lt;p&gt;In the pair of combo boxes above the code window, the left-hand combo box always says global scope, even if the text cursor is in the middle of a class's code. &amp;nbsp;The class name cannot be selected. &amp;nbsp;The right-hand combo box is empty and nothing can be selected. &amp;nbsp;Today this problem is happening only with derived classes but base classes are working.&lt;/p&gt;
&lt;p&gt;Anyway, Intellisense gets rebroken every time it gets rebuilt. &amp;nbsp;Please, is there any way to get Intellisense working again?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8637956" width="1" height="1"&gt;</description></item><item><title>re: Some C++ Gotchas</title><link>http://blogs.msdn.com/b/vcblog/archive/2008/06/05/some-c-gotchas.aspx#8623274</link><pubDate>Fri, 20 Jun 2008 01:16:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8623274</guid><dc:creator>Steve Nuchia</dc:creator><description>&lt;p&gt;Regarding the compiler &amp;quot;calling the wrong function&amp;quot;, I recently spent half a day chasing around in circles on an unrelated problem that will match the same search terms.&lt;/p&gt;
&lt;p&gt;For functions with identical object code and at sufficiently high optimization levels, the linker will combine the bodies. &amp;nbsp;When it does, the debugger, performance profiler, etc will pick one of the names more-or-less at random. &amp;nbsp;It looks very much like the wrong function got called.&lt;/p&gt;
&lt;p&gt;Caveat Debugger.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8623274" width="1" height="1"&gt;</description></item><item><title>re: Some C++ Gotchas</title><link>http://blogs.msdn.com/b/vcblog/archive/2008/06/05/some-c-gotchas.aspx#8600049</link><pubDate>Sun, 15 Jun 2008 11:04:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8600049</guid><dc:creator>Norman Diamond</dc:creator><description>&lt;p&gt;Uh yeah, it went to bool because my parentheses were in the wrong place. &amp;nbsp;Sorry to disturb some number of readers and blog owner.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8600049" width="1" height="1"&gt;</description></item></channel></rss>