This shows you the differences between two versions of the page.
dss:laboratoare:07 [2019/07/03 16:06] razvan.nitu1305 [Interfacing to C] |
dss:laboratoare:07 [2021/07/19 10:08] (current) razvan.nitu1305 [Vibe.d] |
||
---|---|---|---|
Line 193: | Line 193: | ||
} | } | ||
</code> | </code> | ||
+ | |||
+ | |||
===== Exercises ==== | ===== Exercises ==== | ||
Line 203: | Line 205: | ||
<note hint> | <note hint> | ||
- | How are array represented in D? But in C? | + | How are arrays represented in D? But in C? |
</note> | </note> | ||
Line 210: | Line 212: | ||
- Write a C function, called **sumMembers** that receives a parameter of type **struct List3** that packs 3 integer values and computes the sum of the 3 members. Define struct Node and a main function that calls **sumMembers**. | - Write a C function, called **sumMembers** that receives a parameter of type **struct List3** that packs 3 integer values and computes the sum of the 3 members. Define struct Node and a main function that calls **sumMembers**. | ||
- Reimplement **sumMembers** in D by cut-pasting the original code. When linking the objects try using both **gcc** and **dmd**. What happens? | - Reimplement **sumMembers** in D by cut-pasting the original code. When linking the objects try using both **gcc** and **dmd**. What happens? | ||
- | - Redesign **sumMembers** by initializing a builtin array from the members and calling the library function [[sum|https://dlang.org/phobos/std_algorithm_iteration.html#sum]] on it. Before calling sum, manually add 5 and 6 to the array by using the concatenation equals operator "~=". When linking, try using both **gcc** and **dmd**. What happens? Why? | + | - Redesign **sumMembers** by initializing a builtin array from the members and calling the library function [[https://dlang.org/phobos/std_algorithm_iteration.html#sum|sum]] on it. Before calling sum, manually add 5 and 6 to the array by using the concatenation equals operator "~=". When linking, try using both **gcc** and **dmd**. What happens? Why? |
- Compile the D code with betterC. What happens? Why? | - Compile the D code with betterC. What happens? Why? | ||