Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / ctest / ctdecl / decl.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  *
5  */
6
7 /* Author: E.G. Keizer */
8
9 char rcs_id[] = "$Id: decl.c,v 2.3 1994/06/24 12:07:39 ceriel Exp $" ;
10
11 /* Test a few declaration features */
12 /* Such as:
13         forward function declarations,
14         redeclarations,
15         pointer to function declarations.
16 */
17
18 static int      sqr() ; /* forward declarations */
19 extern int      sqrt();
20
21 main() {
22         fdcl() ;
23         hidden() ;
24         return 0 ;
25 }
26
27 fdcl() {
28         int (*a[2])() ;
29
30         printf("sqr(4) %d\n",sqr(4)) ;
31
32         a[0]=sqr ; a[1]=sqrt ;
33         printf("(*a[0])(16) %d\n",(*a[0])(16) ) ;
34         printf("(*a[1])( (*a[0])(3) ) %d\n", (*a[1])( (*a[0])(3) ) ) ;
35 }
36
37 static int sqr(par) int par ; {
38         return par*par ;
39 }
40
41 int sqrt(par) int par ; {
42         int x1,x2 ;
43         int i ;
44
45         if ( par<0 ) return -1 ;
46         x1 = par ;
47         i=0 ;
48         do {
49                 x2 = x1 ;
50                 x1 = ( x2*x2 + par ) / (2*x2) ;
51                 if ( i++>=100 ) return -2 ;
52         } while ( ( x2<x1 ? x1-x2 : x2-x1 ) > 0 ) ;
53         return (x1+x2)/2 ;
54 }
55
56 int a = -8 ;
57
58 hidden() {
59         hide() ;
60         printf("a outside hide %d\n",a) ;
61 }
62
63 int hide() {
64         int a ;
65
66         a = 4 ;
67         printf("a in hide %d\n",a) ;
68         {
69                 int a ;
70
71                 a = 16 ;
72                 printf("a in in hide %d\n",a) ;
73
74         }
75         printf("a in hide %d\n",a) ;
76 }