z/OS Language Environment Writing Interlanguage Communication Applications
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Sample C to C++ applications

z/OS Language Environment Writing Interlanguage Communication Applications
SA38-0684-00

Figure 1. C++main routine
/* Module/File Name:  EDCCXC  */                                          
 /*********************************************************************/   
 /* CPROGRAM, compile with rent and longname                          */   
 /*********************************************************************/   
 #include <stdio.h>       
 #include <stdlib.h>   
                                                                           
 typedef struct {                                                          
   int length;                                                             
   int width;                                                              
 } rectngl;                                                                
                                                                           
 extern void printrec( rectngl r );                                        
 extern void change_width( rectngl* r , int w);                            
                                                                           
 int CFUNC( rectngl  *mine )                                               
 {                                                                         
   int rc;
                                                                           
   printrec( *mine);
   change_width( mine, 5);
                                                                           
 #ifdef debug
   printrec( *mine);
 #endif                                                                    

   printrec( *mine);

   if (mine->width !=5)
     return(1);
   else
     return(0);
                                                                 
}                                                                
Figure 2. Csubroutine
 /* Module/File Name:  EDCCXCX   */                                        
 /*********************************************************************/   
 /* CXXPROG - prelink with CPROG                                      */   
 /*********************************************************************/   
 #include <stdio.h>       
 #include <stdlib.h>                                                         
                                                                           
 #include "verify.h"                                                       
                                                                           
 class rectangle {                                                         
   public:                                                                 
     int length;                                                           
     int width;                                                            
                                                                           
     rectangle(int l, int w ) { length = l; width = w; }                   
     void show()                                                           
     { printf("Length: %d  Width: %d\n",length,width); }
     void set_width( int size ) { width=size; }                            
     void set_length( int size) { length=size; }                           
 };                                                                        
                                                                           
 extern "C" {                                                              
   int CFUNC( rectangle  *small );                                         
   void printrec( rectangle r ) { r.show();};                              
   void change_width( rectangle* r, int nw) { r->set_width(nw);};          
 };                                                                        
                                                                           
 int main( )                                                               
 {                                                                         
   int rc;                                                                 
                                                                           
   rectangle myrec(10,2);                                                  
                                                                           
   rc=CFUNC( &myrec);
                                                                           
   if (rc == 1)                                                            
     fail(__FILE__,__LINE__);
   else                                                                    
     check(__FILE__);
 }                                                                         

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014