![]() |
|
|
#1 |
![]() 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.
|
|
|
|
|
|
#2 |
![]() Join Date: Feb 2010
Posts: 1,336 (1.12/day)
Thanks: 1,381
Thanked 272 Times in 190 Posts
|
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 |
|
|
|
| The Following User Says Thank You to hellrazor For This Useful Post: |
|
|
#3 |
![]() 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?
|
|
|
|
|
|
#4 | |
|
Benevolent Dictator
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 13,793 (4.18/day)
Thanks: 184
Thanked 10,293 Times in 3,176 Posts
|
Quote:
your variables end up in some random piece of memory where they end up with the value that was previously in that memory cell |
|
|
|
|
|
|
#5 |
![]() 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?
|
|
|
|
|
|
#6 |
|
Benevolent Dictator
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 13,793 (4.18/day)
Thanks: 184
Thanked 10,293 Times in 3,176 Posts
|
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
|
|
|
|
| The Following User Says Thank You to W1zzard For This Useful Post: |
|
|
#7 |
![]() 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?
|
|
|
|
|
|
#8 |
![]() Join Date: Sep 2008
Location: Jerusalem, Israel
Posts: 2,121 (1.24/day)
Thanks: 213
Thanked 481 Times in 347 Posts
|
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. |
|
|
|
| The Following User Says Thank You to Yukikaze For This Useful Post: |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|
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 |