DEV Community

Cover image for The Secret Life of Garbage Values, Docker Containers, and a.out
joyeta jahan
joyeta jahan

Posted on

The Secret Life of Garbage Values, Docker Containers, and a.out

Notes

Notes and insights from lecture Array in CS50

  • Garbage variable: the default value of a variable before we initialize it (aka manually set a value to our declared variable). It gets the default value from previous variable that was stored in the same places (aka same bits) in the computer RAM your variable stays now. So for example, if I declare a variable called X, don’t initialize it then computer gives it a default value but that value comes from a previous variable (let’s say Y) that occupied the same space in the memory as your variable now (much like if we rent a house and there are some stuff leftover by the previous tenant, when we enter we clean it, throw everything out).
  • Break point: A point we add in our code literally when we use cs50 debugger. In technical term, it is a point where debugger actually stops the CPU from executing a line of code
  • local variables: the variables that are only available and exist within a limited scope of a program (for example in C, it is the variables inside the curly braces of a function so if we declare a variable in a function but then call the same variable in a different function the compiler will throw an error)
  • open source: the code that is written by somebody else but is open to use for other programmers and developers without any cost and even allowed to update it in our own computer and make our sort of custom made software (though we need the creators permission called a pull request if we need to make change in THEIR code and want everyone who downloads it afterwards has your custom made version)
  • command line: aka the terminal aka the text based interface where we write commands (don’t know the under the hood or technical definition of it)
  • command: the commands we write to make the computer do something (text equivalanet of clicking on a button)
  • command line argument: the extra inputs we write with the commands

Insight

  • Something interesting about garbage values. If you declare a variable then it gets the value of the previous variable that occupied the same memory space as a different variable. However, while doing CS50 I noticed that if we declare a variable and wait for user input in a variable called “h”, it has a default value sure, then the user assigns it a number, but if we close the program and run it again, it does not show the user variable as default value, it shows another large random number. Here is why, in a local setting (while developing a program locally), the computer memory gets reallocated again and again so if there is even a milisecond difference between the first time I run my program and the second time I run it then the space has already been allocated to some other program or software running in the background and when I run it again I see another garbage value. Also modern operating systems do something called ASLR or something which means my variable does not get allocated the same space in the memory twice, so it always has a default garbage value before my program actually initializes it manually. Interesting! But because CS50 cloud is ran in an controlled environment the same garbage value can reappeare again and again since everything in running on something called docker container which contains…. everything of your program I think.

  • If I click on step into for a line that is calling a function then it goes to the actual function aka debug the function itself but if I click on step into for a line of code that is NOT calling a funciton then it is just going to act like “step over” aka execute and go to next line in CS50 Debugger

  • If I have a breakpoint in the code but don’t use the debugger, just run it as it is then the compiler won’t throw an error

  • CS50 Debugging list to use in order: printf, speaking to an actual rubber duck, debug50 and finally cs50 rubber duck AI

  • When I use clang hello.c command in the terminal of vscode cs50 then it creates a file a.out. However I thought since I had two files (hello and buggy) then what happens if I compile the other file buggy.c? Cause David said clang only creates the execution file named a.out. So if I compile two files then does it create 2 .out files? Turns out, no. It doesn’t. It just changes the contents of the a.out aka where before it had the machine code for my hello.c file now it had the machine code version of buggy file. There were never two a.out files.

Top comments (0)