Call a function: Difference between revisions

→‎{{header|C}}: all talk, no code
m (Since we're adding links...)
(→‎{{header|C}}: all talk, no code)
Line 60:
Mixed := H(A, Fun=>F'Access); </lang>
 
=={{header|C}}==
<lang c>/* function with no argument */
f();
 
/* fix number of arguments */
g(1, 2, 3);
 
/* Optional arguments: err...
Feel free to make sense of the following. I can't. */
int op_arg();
int main()
{
op_arg(100);
op_arg(1, 2);
return 0;
}
int op_arg(int a, int b)
{
printf("%d %d\n", a, b);
return a;
} /* end of sensible code */
 
/* Variadic function: how the args list is handled solely depends on the function */
void h(int a, ...)
{
va_list ap;
va_start(ap);
...
}
/* call it as: (if you feed it something it doesn't expect, don't count on it working) */
h(1, 2, 3, 4, "abcd", (void*)0);
 
/* named arguments: no such thing */
/* statement context: is that a real phrase? */
 
/* as a first-class object (i.e. function pointer) */
printf("%p", f); /* that's the f() above */
 
/* return value */
double a = asin(1);
 
/* built-in functions: no such thing. Compiler may interally give special treatment
to bread-and-butter functions such as memcpy(), but that's not a C built-in per se */
 
/* subroutines: no such thing. You can goto places, but I doubt that counts. */
 
/* Functions always pass by value. Pointers *sort of* work like references, though. */</lang>
=={{header|Icon}} and {{header|Unicon}}==
Icon and Unicon have generalized procedures and syntax that are used to implement functions, subroutines and generators.
Anonymous user