Tutorial by Examples: sin

You can pass a pointer variable to a method as parameter. The following example illustrates this: using System; namespace UnsafeCodeApplication { class TestPointer { public unsafe void swap(int* p, int *q) { int temp = *p; *p = *q; *q = temp; ...
In C#, an array name and a pointer to a data type same as the array data, are not the same variable type. For example, int *p and int[] p, are not same type. You can increment the pointer variable p because it is not fixed in memory but an array address is fixed in memory, and you can't increment th...
Simple single port RAM with async read/write operations module ram_single_port_ar_aw #( parameter DATA_WIDTH = 8, parameter ADDR_WITDH = 3 )( input we, // write enable input oe, // output enable input [(ADDR_WITDH-1):0] waddr, // ...
It is (almost always) a bad idea to call System.gc(). The javadoc for the gc() method specifies the following: "Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick re...
To interact with the filesystem you use the methods of the class Files. Checking existence To check the existence of the file or directory a path points to, you use the following methods: Files.exists(Path path) and Files.notExists(Path path) !Files.exists(path) does not neccesarily have t...
C# inherits from C and C++ the usage of the symbol -> as a means of accessing the members of an instance through a typed pointer. Consider the following struct: struct Vector2 { public int X; public int Y; } This is an example of the usage of -> to access its members: Vector2...
Use .PHONY to specify the targets that are not files, e.g., clean or mrproper. Good example .PHONY: clean clean: rm *.o temp Bad example clean: rm *.o temp In the good example make knows that clean is not a file, therefore it will not search if it is or not up to date and will ex...
This example uses C++14 and boost::any. In C++17 you can swap in std::any instead. The syntax we end up with is: const auto print = make_any_method<void(std::ostream&)>([](auto&& p, std::ostream& t){ t << p << "\n"; }); super_any<decltype(print...
We can change the tasks execution order with the dependsOn method. task A << { println 'Hello from A' } task B(dependsOn: A) << { println "Hello from B" } Adding `dependsOn: causes: task B depends on task A Gradle to execute A task everytime before the B ta...
task A << { println 'Hello from A' } task B << { println 'Hello from B' } B.dependsOn A It is an alternative way to define the dependency instead of using the task name. And the output is the same: > gradle -q B Hello from A Hello from B
context.globalCompositeOperation = "destination-in" "destination-in" compositing clips existing drawings inside a new shape. Note: Any part of the existing drawing that falls outside the new drawing is erased. context.drawImage(picture,0,0); context.globalCompositeOperation...
context.globalCompositeOperation = "source-in"; source-in compositing clips new drawings inside an existing shape. Note: Any part of the new drawing that falls outside the existing drawing is erased. context.drawImage(oval,0,0); context.globalCompositeOperation='source-in'; // pictu...
We're using a toplevel guard in our route config to catch the current user on first page load, and a resolver to store the value of the currentUser, which is our authenticated user from the backend. A simplified version of our implementation looks as follows: Here is our top level route: export c...
Considering that most debuggers are not aware of #define macros, but can check enum constants, it may be desirable to do something like this: #if __STDC_VERSION__ < 199900L typedef enum { false, true } bool; /* Modern C code might expect these to be macros. */ # ifndef bool # define bool bo...
Jumping out of nested loops would usually require use of a boolean variable with a check for this variable in the loops. Supposing we are iterating over i and j, it could look like this size_t i,j; for (i = 0; i < myValue && !breakout_condition; ++i) { for (j = 0; j < mySecondVa...
Returning a value One commonly used case: returning from main() #include <stdlib.h> /* for EXIT_xxx macros */ int main(int argc, char ** argv) { if (2 < argc) { return EXIT_FAILURE; /* The code expects one argument: leave immediately skipping t...
Immediately continue reading on invalid input or break on user request or end-of-file: #include <stdlib.h> /* for EXIT_xxx macros */ #include <stdio.h> /* for printf() and getchar() */ #include <ctype.h> /* for isdigit() */ void flush_input_stream(FILE * fp); int main(v...
Given: x <- as.matrix(mtcars) One can use heatmap.2 - a more recent optimized version of heatmap, by loading the following library: require(gplots) heatmap.2(x) To add a title, x- or y-label to your heatmap, you need to set the main, xlab and ylab: heatmap.2(x, main = "My main t...
Unwind Segues Unwind Segues give you a way to “unwind” the navigation stack and specify a destination to go back to. The signature of this function is key to Interface Builder recognizing it. It must have a return value of IBAction and take one parameter of UIStoryboardSegue. The name of the ...
Overview Gtk+ supports a workflow where the task of user interface design and the task of programming are decoupled. Although the user interface elements such as buttons, menus, layout etc. can be directly added from code, this approach not only clutters the code, but also makes changing the UI for...

Page 93 of 161