// filename:c2011-6-9-1-ex.c
// original examples and/or notes:
// 		(c) ISO/IEC JTC1 SC22 WG14 N1570, April 12, 2011
// 			C2011 6.9.1 Function definitions
// compile and output mechanism:
// 		(c) Ogawa Kiyoshi, kaizen@gifu-u.ac.jp, December.xx, 2013
// compile errors and/or wornings:
// 		(c) Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn)
// 			Target: x86_64-apple-darwin11.4.2 //Thread model: posix
// 		(c) LLVM 2003-2009 University of Illinois at Urbana-Champaign.
#include <stdio.h>
// Note 141) 
typedef int F(void); // type F is ‘‘function with no parameters
// returning int’’
F f, g; // f and g both have type compatible with F
// ** F f { /* ... */ } // WRONG: syntax/constraint error //**
//c2011-6-9-1-ex.c:16:4: error: expected ';' after top level declarator
//F f { /* ... */ } // WRONG: syntax/constraint error
//   ^
//;

//** F g() { /* ... */ } // WRONG: declares that g returns a function //**
//c2011-6-9-1-ex.c:22:4: error: function cannot return function type 'F' (aka 'int (void)')
//F g() { /* ... */ } // WRONG: declares that g returns a function
//  ^

int f(void) { /* ... */ return 0;} // RIGHT: f has type compatible with F
int g() { /* ... */ return 0;} // RIGHT: g has type compatible with F
F *e(void) { /* ... */ return 0;} // e returns a pointer to a function
F *((e1))(void) { /* ... */return 0; } // same: parentheses irrelevant
int (*fp)(void); // fp points to a function that has type F
F *Fp; //Fp points to a function that has type F

// Example 1
extern int max(int a, int b)
{
return a > b ? a : b;
}
extern int max1(a, b)
int a, b;
{
return a > b ? a : b;
}

// Example 2

int f(void);
/* ... */

void g1(int (*funcp)(void))
{
/* ... */
(*funcp)(); /* or funcp(); ... */
}

void g2(int func(void))
{
/* ... */
func(); /* or (*func)(); ... */
}
int main(void)
{
g1(f); g2(f);
return printf("6.9.1 Function definitions %d %d\n",max(1,2),f());	
}
// output may be
// 6.9.1 Function definitions 2 0