Advertisement
Pillager86

Cursed Code

May 6th, 2020
2,956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.38 KB | None | 0 0
  1. import std.stdio;
  2. import std.traits;
  3.  
  4. alias FooFn = void function(int) nothrow;
  5.  
  6. void callFoo(FooFn fooFn)
  7. {
  8.     fooFn(42);
  9. }
  10.  
  11. void foo(int x)
  12. {
  13.     writeln(x);
  14. }
  15.  
  16. void bar(string s)
  17. {
  18.     writeln(s);
  19. }
  20.  
  21. void main(string [] args) {
  22.     FooFn fooFn = cast(SetFunctionAttributes!(FooFn, functionLinkage!FooFn, FunctionAttribute.nothrow_))&bar;
  23.     callFoo(fooFn);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement