Advanced Search
Search Results
297 total results found
5. Pointers and Functions
Pointers are essential for functions to modify variables from the calling code and to work efficiently with arrays. 5.1 Pass by Value vs Pass by Reference Pass by Value (Without Pointers): #include <stdio.h> void tryToChange(int x) { x = 100; // Only cha...
6. Pointers and Strings
In C, strings are arrays of characters, so pointers work naturally with strings. 6.1 String Representation char str1[] = "Hello"; // Array notation char *str2 = "Hello"; // Pointer notation // Both represent the same thing in memory: // 'H' 'e' 'l' '...
7. Dynamic Memory Allocation & Array
7.1 Introduction to Dynamic Memory Up until now, we've used static memory allocation where array sizes must be known at compile time: int arr[100]; // Size fixed at compile time Problems with static allocation: Waste memory if you allocate too much Run out ...
8. Common Pointer Pitfalls and Best Practices
8.1 Uninitialized Pointers WRONG: int *ptr; // Uninitialized - contains garbage address *ptr = 42; // DANGER! Writing to unknown memory location // May cause segmentation fault CORRECT: int *ptr = NULL; // Initialize to NULL int num ...
9. Practical Examples with Dynamic Memory
9.1 Dynamic Array with User Input #include <stdio.h> #include <stdlib.h> int main() { int n, *arr; printf("How many numbers do you want to enter? "); scanf("%d", &n); // Allocate memory arr = (int*)malloc(n * sizeof(int)); if...
Introduction to Looping Constructs
Introduction to Looping Constructs Looping constructs are VHDL instructions that allow a program to repeat the same block of code, a process known as iteration (similar to C). Loops in VHDL are divided into two main categories based on how they function and wh...
For Loop
For Loop The for loop is the most common type of sequential loop in VHDL. It is used to repeat a block of code a specific, pre-determined number of times. This makes it ideal for tasks where you know exactly how many iterations you need, such as processing the...
While Loop
While Loop The while loop is used where the number of repetitions is not known from the start. A while loop continues to execute as long as a specified condition is true. Syntax The basic structure of a while loop is: loop_label: while <condition> loop --...
Loop Control - Next & Exit
Loop Control - Next & Exit The two control statements, next and exit, allow you to skip an iteration or terminate the loop entirely, giving you more precise control over your sequential code. These statements can be used in both for and while loops. One, The ...
For-Generate Loop
The Concurrent 'for-generate' Loop We now switch from sequential loops to a concurrent one. The for-generate statement is not a loop that executes over time inside a process. Instead, it's a command that tells the synthesizer to create multiple copies of hardw...
When & Which
When & Which? Comparison Feature for Loop while Loop for-generate Statement Execution Sequential Sequential Concurrent Usage Location Inside a process Inside a process Outside a process Iteration Fixed number of times Repeats while a condition is tr...
1. Introduction to User-Defined Data Types
1.1 Why User-Defined Types? In previous modules, we learned about basic data types like int, float, char, etc. These are sufficient for simple programs, but real-world applications often require more complex data structures. Example Problem: Suppose you want t...
2. Structures (struct)
2.1 What is a Structure? A structure is a user-defined data type that groups variables of different types under a single name. Think of it as creating your own custom data type. Python vs C Comparison: Python C Uses classes or dictionaries Uses struct ...
3. Enumerations (enum)
3.1 What is an Enumeration? An enumeration is a user-defined data type consisting of a set of named integer constants. Enums make code more readable by replacing "magic numbers" with meaningful names. Python vs C Comparison: Python C No built-in enum (u...
4. Type Definitions (typedef)
4.1 What is typedef? typedef creates aliases (alternative names) for existing data types. It makes code more readable and easier to maintain. Basic Syntax: typedef existing_type new_name; 4.2 typedef with Basic Types // Create aliases for basic types typedef ...
5. File Input/Output
5.1 Why File I/O? So far, all our programs lose their data when they terminate. File I/O allows programs to: Save data permanently Read data from external sources Create logs and reports Share data between programs Python vs C File Operations: Python C ...
Procedure
In VHDL, a procedure is a type of language construct used to group several statements and specific tasks into a single block of code. Procedures help in organizing and simplifying the understanding of complex VHDL designs. A procedure in VHDL is similar to a v...
Function
In VHDL, a function is a subprogram used to perform calculations or data processing that returns a single value as a result. Functions in VHDL are similar to functions in traditional programming languages such as C or Java, where the main purpose is to compute...
Impure Function
In VHDL, an impure function is a special type of function that is allowed to read or modify signals, variables, or states outside its local scope. Unlike a pure function, which always produces the same output for the same input (no side effects), an impure fun...
Procedure, Function and Impure Function Synthesis
In VHDL, both "function" and "procedure" can be used in hardware descriptions, but it should be understood that hardware synthesis is usually more suitable for implementations based on deterministic and synchronous behavior. Therefore, there are several limita...