PRL1013 Problem Solving in Computing PDF

Summary

This document provides an overview of compiler, execution, and debugging concepts in computer science. It covers topics like the compilation process, different types of compilers, and common debugging techniques. The document also discusses execution flow and the importance of optimizing code for performance.

Full Transcript

PRL1013 Problem Solving in Computing DEVELOPING THE SOLUTION SUB-TOPICS COVER IN LEARNING UNIT Coding Compile Execution Debugging PART 1.2 COMPILER, EXECUTION & DEBUDDING Definition WHAT IS Process of converting source code...

PRL1013 Problem Solving in Computing DEVELOPING THE SOLUTION SUB-TOPICS COVER IN LEARNING UNIT Coding Compile Execution Debugging PART 1.2 COMPILER, EXECUTION & DEBUDDING Definition WHAT IS Process of converting source code written in a high-level programming language like C++ into machine code that COMPILATION? a computer can understand and run. Purpose To change human-readable code into a format that computers can understand. THE COMPILATION PROCESS Preprocessing Manages directives (e.g., #include, #define) and gets the code ready for 1 compilation. Compilation 2 Turns the preprocessed code into assembly code. THE COMPILATION PROCESS Assembly 3 Changes assembly code into machine code, creating an object file. Linking 4 Joins object files with libraries to make the final executable file. WHAT IS Definition A specific program or tool that performs COMPILER? the compilation process. A compiler is like a translator takes a book written in one language and translates it into another language that people can understand. COMMON C++ GCC (GNU Compiler Collection) COMPILERS Multi-language Support: Compiles C, C++ and more. Cross-Platform: Works on various architectures. Open-source: Free and community-driven. COMMON C++ Clang COMPILERS Fast Compiler: Known for speed and efficiency. Language Support: Focuses on C, C++ and Objective-C. Error Diagnostics: Provides detailed error messages. COMMON C++ MSVC (Microsoft Visual C++) COMPILERS Microsoft Tool: Designed for Windows OS. Visual Studio Integration: Comprehensive development environment. C/C++ Support: Robust tools for Windows application development. TYPES OF COMPILATION Ahead-of-Time Just-in-Time (JIT) Interpretation (AOT) Compiles all code Compiles code during Runs/Executes high- before running/execution level code line by line running/execution Error Checking: Identifies syntax and IMPORTANCE OF type errors. COMPILATION Optimization: Compilers can optimize code for performance. Portability: Allows high-level code to run on different hardware. Definition WHAT IS Process of running a compiled program on a computer's processor to carry out tasks and produce results. EXECUTION? Purpose To change the compiled machine code into actions done by the computer, like calculations, data processing, and showing results. EXECUTION VS COMPILATION Execution Compilation Runs the compiled machine code Translates high-level code into to perform the program's machine code before execution. functions. Involves dynamic resource Focuses on syntax correctness management EXECUTION FLOW Loading 1 The operating system (OS) loads the executable file into memory. Linking 2 If dynamic libraries are required, the OS links them at runtime. EXECUTION FLOW Initialization 3 The program initializes variables and sets up the execution environment. Execution 4 The CPU executes instructions sequentially Termination 5 The program finishes execution and releases resources. Local Execution Running programs on personal or Types of Execution server computers. Environments Online Compilers Web-based environments that compile and execute code. Embedded Systems Running C++ programs on specialized hardware. Runtime Errors: Errors that occur during execution. COMMON Logical Errors: The program runs without crashing but EXECUTION produces incorrect results. Resource Leaks: Failing to release allocated resources ISSUES can lead to performance issues. Performance Bottlenecks: Inefficient algorithms can slow down execution. Definition WHAT IS Process of identifying, isolating, and fixing bugs or errors in a program. DEBUGGING? Purpose To improve program reliability and performance by resolving issues. Syntax Errors Mistakes in code structure that Common Types prevent compilation. of Bugs Runtime Errors Errors that occur during program execution. Logical Errors Mistakes in logic that produce incorrect results. Print Statements Use print statements to trace variable Debugging values. Techniques Breakpoints Set breakpoints to pause execution and inspect variables. Step Execution Execute code line by line to observe behavior. Understand the Code: Familiarize yourself with the code structure. BEST PRACTICES Reproduce the Bug: Ensure you can consistently reproduce the issue. FOR Use Version Control: Track changes to identify when bugs were introduced. DEBUGGING Take Breaks: Clear your mind if you're stuck. Document Findings: Keep notes on identified bugs and fixes.

Use Quizgecko on...
Browser
Browser