Call a function: Difference between revisions

→‎{{header|C}}: Added possible named argument implementation
(Add Elixir)
(→‎{{header|C}}: Added possible named argument implementation)
Line 356:
h(1, 2, 3, 4, "abcd", (void*)0);
 
/* named arguments: nothis suchis thingonly */possible through some pre-processor abuse
*/
/* statement context: is that a real phrase? */
struct v_args {
int arg1;
int arg2;
char _sentinel;
};
 
void _v(struct v_args args)
{
printf("%d, %d\n", args.arg1, args.arg2);
}
 
#define v(...) _v((struct v_args){__VA_ARGS__})
 
v(.arg2 = 5, .arg1 = 17); // prints "17,5"
/* NOTE the above implementation gives us optional typesafe optional arguments as well (unspecified arguments are initialized to zero)*/
v(.arg2=1); // prints "0,1"
v(); // prints "0,0"
 
/* as a first-class object (i.e. function pointer) */
Line 372 ⟶ 389:
/* Scalar values are passed by value by default. However, arrays are passed by reference. */
/* Pointers *sort of* work like references, though. */</lang>
 
 
=={{header|C Sharp}}==