Low level programming in ada. Capture a signal,
https://gitlab.com/alaindevos/adatut/-/tree/main/11_signal/src?ref_type=heads
https://gitlab.com/alaindevos/adatut/-/tree/main/11_signal/src?ref_type=heads
Ada its quite easy:One simple example . In C you can dereference a null pointer & a pointer pointing to the sky. Never possible in F# or ada
with Ada.Text_IO;
procedure Erroneous is
type Int_Ptr is access Integer;
P : Int_Ptr; -- uninitialized
begin
-- ERRONEOUS EXECUTION
Ada.Text_IO.Put_Line (Integer'Image (P.all));
end Erroneous;
open Microsoft.FSharp.NativeInterop
#nowarn "9" // allow NativePtr usage
let demo () =
// Allocate stack memory for an int, but DO NOT initialize it
let p = NativePtr.stackalloc<int> 1
// ERRONEOUS / UNDEFINED BEHAVIOR
let x = NativePtr.read p
printfn "%d" x
demo ()
Ada its quite easy:
Code:with Ada.Text_IO; procedure Erroneous is type Int_Ptr is access Integer; P : Int_Ptr; -- uninitialized begin -- ERRONEOUS EXECUTION Ada.Text_IO.Put_Line (Integer'Image (P.all)); end Erroneous;
F# is just .NET so the typical bindings marshal errors allow it too.
Code:open Microsoft.FSharp.NativeInterop #nowarn "9" // allow NativePtr usage let demo () = // Allocate stack memory for an int, but DO NOT initialize it let p = NativePtr.stackalloc<int> 1 // ERRONEOUS / UNDEFINED BEHAVIOR let x = NativePtr.read p printfn "%d" x demo ()
And since languages other than C or C++ need a *shedload* of bindings, this kind of dangerous stuff is very easy (and necessary) to creep in.
String: type == std::string;
auto& Cout = std::cout;
#define Format std::format
greet: (name: String) = {
Cout << Format("Hello, {}\n", name);
}
sum: (a: i32, b: i32) -> i32 = {
sum := a + b; // Type inference with :=
return sum;
}
main: () = {
x: String = "world";
greet(x);
s:=sum(10, 20);
Cout << Format("Sum : {}\n", s);
}