techPowerUp! Forums

Go Back   techPowerUp! Forums > Software > Programming & Webmastering

Reply
 
Thread Tools
Old Jan 6, 2012, 02:23 AM   #1
boogerlad
75 Posts
 
Join Date: Jun 2006
Posts: 193 (0.08/day)
Thanks: 13
Thanked 12 Times in 11 Posts

c++ compiler optimizations

Hi all, I've been debugging my very basic test program, using eclipse and gcc 4.6.2. I noticed that when I put breakpoints on all lines of my code, and then debug, even on the first line printing "Hello World!", my variable xt is already initialized to some bizarre value. And so is my derp variable. All compiler optimizations are off. Oh and btw does anyone know what the (x) symbol means? I circled it.
boogerlad is offline  
Reply With Quote
Old Jan 6, 2012, 07:11 AM   #2
hellrazor
1000 Posts
 
hellrazor's Avatar
 
Join Date: Feb 2010
Posts: 1,336 (1.12/day)
Thanks: 1,381
Thanked 272 Times in 190 Posts

System Specs

It's initialized to gibberish because that's what the memory was when the program took it for it's own use.
__________________
"Doom means two things: demons and shotguns." -John Carmack
hellrazor is offline  
Reply With Quote
The Following User Says Thank You to hellrazor For This Useful Post:
Old Jan 6, 2012, 04:07 PM   #3
boogerlad
75 Posts
 
Join Date: Jun 2006
Posts: 193 (0.08/day)
Thanks: 13
Thanked 12 Times in 11 Posts

but are all variables initialized to something even before their statement?
boogerlad is offline  
Reply With Quote
Old Jan 6, 2012, 04:34 PM   #4
W1zzard
Benevolent Dictator
 
W1zzard's Avatar
 
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 13,793 (4.18/day)
Thanks: 184
Thanked 10,293 Times in 3,176 Posts
Send a message via ICQ to W1zzard Send a message via AIM to W1zzard Send a message via MSN to W1zzard

System Specs

Quote:
Originally Posted by boogerlad View Post
but are all variables initialized to something even before their statement?
ALWAYS initialize variables. the system does not guarantee any value for it. could be 0 in your testing and end up as something else on your customer's system

your variables end up in some random piece of memory where they end up with the value that was previously in that memory cell
W1zzard is offline  
Reply With Quote
Old Jan 6, 2012, 04:37 PM   #5
boogerlad
75 Posts
 
Join Date: Jun 2006
Posts: 193 (0.08/day)
Thanks: 13
Thanked 12 Times in 11 Posts

but the breakpoint is still at the helloworld line! Why are there even variables that exists? Don't they only come into existence on the line they are declared, ie line 2 and 6?
boogerlad is offline  
Reply With Quote
Old Jan 6, 2012, 04:39 PM   #6
W1zzard
Benevolent Dictator
 
W1zzard's Avatar
 
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 13,793 (4.18/day)
Thanks: 184
Thanked 10,293 Times in 3,176 Posts
Send a message via ICQ to W1zzard Send a message via AIM to W1zzard Send a message via MSN to W1zzard

System Specs

Quote:
Originally Posted by boogerlad View Post
but the breakpoint is still at the helloworld line! Why are there even variables that exists? Don't they only come into existence on the line they are declared, ie line 2 and 6?
the variable always exists (in the same function), in a way that the program knows where its memory location is. you obviously can't use it before you declare it but that's a language construct
W1zzard is offline  
Reply With Quote
The Following User Says Thank You to W1zzard For This Useful Post:
Old Jan 6, 2012, 05:05 PM   #7
boogerlad
75 Posts
 
Join Date: Jun 2006
Posts: 193 (0.08/day)
Thanks: 13
Thanked 12 Times in 11 Posts

Would it still exist at runtime before it has been declared even if the variable was allocated to heap?
boogerlad is offline  
Reply With Quote
Old Jan 6, 2012, 05:16 PM   #8
Yukikaze
2000 Posts
 
Yukikaze's Avatar
 
Join Date: Sep 2008
Location: Jerusalem, Israel
Posts: 2,121 (1.24/day)
Thanks: 213
Thanked 481 Times in 347 Posts

System Specs

Quote:
Originally Posted by boogerlad View Post
Would it still exist at runtime before it has been declared even if the variable was allocated to heap?
Every variable "exists" when you are in the scope of that variable. For things allocated via new/malloc the pointer itself exists as soon as you enter its scope (and may contain some arbitrary value and thus point to an arbitrary location in memory), the actual memory location for the variable you allocate via new/malloc is allocated upon the execution of the new/malloc call. These calls pick a free memory location and assign it for your use. They do no guarantee the contents of the allocated location.
__________________
Cameron: Core i7 2600K 4.5Ghz, MCR220, 2xMCR120, MCP655, ASRock P67 Extreme4, 4GB DDR3, 2xOCZ Vertex 30GB RAID0, GTX470, 2xHD5670, Modu82+ 625W, TT Xaser VI.
Neuromancer: Core i7 975, DFI DK X58-T3eH6, 12GB DDR3 1333Mhz CL6-6-6-15-1T, 3x9600GSO 384MB, Hiper 880W, TT Xaser VI.
Administrator of a 40 core Hadoop cluster.
Yukikaze is offline  
Reply With Quote
The Following User Says Thank You to Yukikaze For This Useful Post:
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Intel's Compiler Ahhzz General Hardware 0 Oct 4, 2011 01:26 PM
Compiler problem in Visual C++ Aleksander Programming & Webmastering 6 Aug 27, 2011 08:51 PM
C++ Compiler for MAC [I.R.A]_FBi Linux / BSD / Mac OS X 0 Mar 17, 2008 06:17 PM
ATI driver optimizations imperialreign Graphics Cards 5 Nov 19, 2007 11:21 AM
Intel optimizes compiler for multithreading DanTheBanjoman News 0 Jun 16, 2005 11:02 AM


All times are GMT. The time now is 09:34 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
no new posts