Annotation of researchv10no/cmd/cfront/ooptcfront/demo/mi.c, revision 1.1

1.1     ! root        1: /* Test nested instantiations in the presence of multiple base classes */
        !             2: 
        !             3:                                           
        !             4: template <class p1, class p2> class b1 {
        !             5: public:
        !             6:   p1 x1 ;
        !             7:   p2 y1 ;
        !             8:   void foo() ;
        !             9: } ;
        !            10: 
        !            11: 
        !            12: template <class p1, class p2> class b2 {
        !            13: public:
        !            14:   p1 x2 ;
        !            15:   p2 y2 ;
        !            16:   void foo() ;
        !            17: } ;
        !            18: 
        !            19: template <class pd1, class pd2> class d :
        !            20:                        public b1<pd1, pd2>, public b2<pd1, pd2> {
        !            21: public:
        !            22:   pd1 *i ;
        !            23:   int check_i(pd1 test) ;
        !            24:   int check_x(pd1 test) ;
        !            25:   int check_y(pd2 test) ;
        !            26: } ;
        !            27: 
        !            28: 
        !            29: // Check access from within a member function
        !            30: template  <class pd1, class pd2> int d<pd1,pd2>::check_i(pd1 test) {
        !            31:   return (*i == test) ;
        !            32: }
        !            33: 
        !            34: 
        !            35: template  <class pd1, class pd2> int d<pd1,pd2>::check_x(pd1 test) {
        !            36:   return ((x1 == test) && (x2 == test+1)) ;
        !            37: }
        !            38: 
        !            39: 
        !            40: template  <class pd1, class pd2> int d<pd1,pd2>::check_y(pd2 test) {
        !            41:   return ((y1 == test) && (y2 == test+1)) ;
        !            42: }
        !            43:   
        !            44:   
        !            45:  
        !            46: #define check(p)  if (!(p))printf("\nerror(%d): test failed at line %d",++error, __LINE__) 
        !            47: 
        !            48: 
        !            49: typedef char *pc ;
        !            50: typedef int *pi ;
        !            51: 
        !            52: extern "C" void printf(...) ;
        !            53: 
        !            54: extern "C" void exit(int) ;
        !            55: 
        !            56: 
        !            57: void end_test(int error) 
        !            58: {
        !            59:   printf ("\n*End Testing %s", __FILE__) ;
        !            60:   if (error)
        !            61:     printf (" *** %d errors ***\n", error) ;
        !            62:   else printf (" no errors detected\n") ;
        !            63:   
        !            64:   exit(error) ;
        !            65: }
        !            66: 
        !            67: main () {
        !            68:   printf ("\n*Begin Testing %s\n", __FILE__) ;
        !            69:   d<int, pc> v1 ;
        !            70:   int i ; char c ; int error = 0 ;
        !            71: 
        !            72:   v1.i = & i ;
        !            73:   v1.x1 = i ;   v1.x2 = i + 1 ;
        !            74:   v1.y1 = & c ; v1.y2 = &c + 1 ;
        !            75: 
        !            76:   check (v1.i == & i) ;
        !            77:   check (v1.x1 == i) ;
        !            78:   check(v1.y1 == & c) ;
        !            79: 
        !            80:   check (v1.check_i (i)) ;
        !            81:   check (v1.check_x (i)) ;
        !            82:   check (v1.check_y (&c)) ;
        !            83: 
        !            84:   end_test(error) ;
        !            85: 
        !            86: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.