str.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. /* Author: E.G. Keizer */
  7. static char rcs_id[]= "$Id$" ;
  8. /* test for structure parameters, assignment and return */
  9. # define ASIZE 26
  10. struct w1 {
  11. int w1_i ;
  12. } ;
  13. struct w2 {
  14. int w2_i ;
  15. long w2_l ;
  16. } ;
  17. struct w3 {
  18. char w3_a[ASIZE] ;
  19. unsigned w3_u ;
  20. } ;
  21. struct w1 es1 ;
  22. struct w1 es2[3] ;
  23. main() {
  24. asst() ;
  25. part() ;
  26. callt() ;
  27. return 0 ;
  28. }
  29. asst() {
  30. /* test structure assignment */
  31. struct w1 st1, st2, *st3 ;
  32. struct w2 s2t1, s2t2, *s2t3 ;
  33. struct w3 s3t1, s3t2, *s3t3 ;
  34. register int i ;
  35. printf("w1\n") ;
  36. st1.w1_i = 506 ;
  37. st2 = st1 ;
  38. printf("\tst2.w1_i %d\n",st2.w1_i) ;
  39. st3 = &st1 ;
  40. printf("\t(*st3).w1_i %d\n",(*st3).w1_i) ;
  41. es1.w1_i = 711 ;
  42. st1 = st2 = es1 ;
  43. printf("\tst1.w1_i %d\n",st1.w1_i) ;
  44. printf("\tst2.w1_i %d\n",st2.w1_i) ;
  45. es2[2] = st1 ;
  46. printf("\tes2[2].w1_i %d\n",es2[2].w1_i) ;
  47. st1.w1_i = -577 ;
  48. es1.w1_i = 577 ;
  49. for ( i=0 ; i<2 ; i++ ) {
  50. st2 = ( i ? st1 : es1 ) ;
  51. printf("\tst2.w1_i %d\n",st2.w1_i) ;
  52. }
  53. st1 = ( i , es1 ) ;
  54. printf("\tst1.w1_i %d\n",st1.w1_i) ;
  55. printf("w2\n") ;
  56. s2t1.w2_i = 18000 ;
  57. s2t1.w2_l = 31415 ;
  58. s2t2 = s2t1 ;
  59. printf("\ts2t2: .w2_i %d .w2_l %ld\n",s2t2.w2_i,s2t2.w2_l) ;
  60. s2t3 = &s2t2 ;
  61. printf("\ts2t3->w2_l %ld\n",s2t3->w2_l) ;
  62. printf("w3\n") ;
  63. for ( i = 0 ; i<ASIZE ; i++ ) {
  64. s3t1.w3_a[i]= 'a'+i ;
  65. }
  66. s3t1.w3_u = 0x8000 ;
  67. s3t2 = s3t1 ;
  68. s3t3 = &s3t1 ;
  69. for ( i = 0 ; i<ASIZE ; i++ ) {
  70. printf("s3t2.w3_a[%2d] %c\n",i,s3t2.w3_a[i]) ;
  71. }
  72. printf("s3t2.w3_u %x\n",s3t2.w3_u) ;
  73. s3t2.w3_u = 1415 ;
  74. for ( i = 0 ; i<ASIZE ; i++ ) {
  75. s3t2.w3_a[i]= 'A'+i ;
  76. }
  77. *s3t3 = s3t2 ;
  78. for ( i = 0 ; i<ASIZE ; i++ ) {
  79. printf("s3t1.w3_a[%2d] %c\n",i,s3t1.w3_a[i]) ;
  80. }
  81. printf("s3t1.w3_u %x",s3t1.w3_u) ;
  82. }
  83. struct w3 epars ;
  84. part() {
  85. /* test structure parameters */
  86. struct w3 pars ;
  87. register i ;
  88. for ( i=0 ; i<ASIZE ; i++ ) {
  89. pars.w3_a[i]=i+1 ;
  90. }
  91. pars.w3_u = 281 ;
  92. printf("\nstructure parameters\n") ;
  93. psc(-1,pars,1000) ;
  94. }
  95. psc(before,str,after) int before, after ; struct w3 str ; {
  96. register int i ;
  97. printf("before %d\n",before) ;
  98. for ( i=0 ; i<ASIZE ; i++ ) {
  99. printf("str.w3_a[%2d]\t%d\n",i,str.w3_a[i]) ;
  100. }
  101. printf("str.w3_u %x\n",str.w3_u) ;
  102. printf("after %d\n",after) ;
  103. }
  104. callt() {
  105. /* test structure valued functions */
  106. extern struct w3 setp1(), setp2() ;
  107. struct w3 myp ;
  108. register int i ;
  109. printf("\nStucture valued functions\n") ;
  110. myp = setp1(ASIZE) ;
  111. printf("myp.w3_a:\n") ;
  112. for ( i=0 ; i<ASIZE ; i++ ) {
  113. printf("\t%2d\t%d\n",i,myp.w3_a[i]) ;
  114. }
  115. myp = setp2() ;
  116. for ( i=0 ; i<ASIZE ; i++ ) {
  117. printf("\t%2d\t%d\n",i,myp.w3_a[i]) ;
  118. }
  119. }
  120. struct w3 setp1(count) {
  121. struct w3 myp ;
  122. if ( count<=0 ) {
  123. return(myp) ;
  124. }
  125. myp = setp1(count-1) ;
  126. myp.w3_a[count-1] = 99-count-1 ;
  127. return(myp) ;
  128. }
  129. static struct w3 myp2 ;
  130. struct w3 setp2() {
  131. struct w3 *w3p ;
  132. register i ;
  133. for ( i=0 ; i<ASIZE ; i++ ) {
  134. myp2.w3_a[i]= 99+i ;
  135. }
  136. w3p = &myp2 ;
  137. return(*w3p) ;
  138. }