home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.os.vms      DEC's VAX* line of computers & VMS.      264,096 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 262,254 of 264,096   
   =?UTF-8?Q?Arne_Vajh=C3=B8j?= to All   
   Re: Fun trick   
   13 Jan 25 13:40:46   
   
   From: arne@vajhoej.dk   
      
   On 1/9/2025 8:01 AM, hb0815 wrote:   
   > On 1/9/25 02:00, Arne Vajhøj wrote:   
   >> Hmmm.   
   >>   
   >> It works in C, but it does not seem to work in   
   >> any other language (tested with Pascal and Fortran).   
   >> ...   
   >> I assume the difference relates to user code main not being   
   >> the real program entry.   
   >   
   > So, make it a main entry.   
   >   
   > This is on Alpha. It should work on IA64 and x86. I don't have access to   
   > any of the latter systems. If this does not work on these systems, I   
   > know how to make it work, anyway.   
   >   
   > $ gdiff -ub lib.pas-orig lib.pas   
      
   > $ gdiff -ub lib.for-orig lib.for   
      
   For those that do not speak diffish:   
      
   $ type prg.c   
   #include    
      
   extern void say();   
      
   int main(int argc, char *argv[])   
   {   
        say();   
        return 0;   
   }   
      
   $ type lib.c   
   #include    
      
   void say()   
   {   
        printf("Hi\n");   
   }   
      
   int main()   
   {   
        printf("This is a shareable image to link against not run\n");   
        return 0;   
   }   
      
   $ cc lib   
   $ link/share=libshr lib + sys$input/opt   
   symbol_vector=(say=procedure)   
   $   
   $ define/nolog libshr sys$disk:[]libshr   
   $ cc prg   
   $ link prg + sys$input/opt   
   libshr/share   
   $   
   $ run prg   
   Hi   
   $ run libshr   
   This is a shareable image to link against not run   
   $ type prg.pas   
   program prg(input,output);   
      
   [external]   
   procedure say; external;   
      
   begin   
       say;   
   end.   
   $ type lib.pas   
   program lib(input, output);   
      
   [global]   
   procedure say;   
      
   begin   
       writeln('Hi');   
   end;   
      
   begin   
       writeln('This is a shareable image to link against not run');   
   end.   
   $ pas lib   
   $ link/share=libshr lib + sys$input/opt   
   symbol_vector=(say=procedure)   
   $   
   $ define/nolog libshr sys$disk:[]libshr   
   $ pas prg   
   $ link prg + sys$input/opt   
   libshr/share   
   $   
   $ run prg   
   Hi   
   $ run libshr   
   This is a shareable image to link against not run   
   $ type prg.for   
          program prg   
          call say   
          end   
   $ type lib.for   
          program lib   
          write(*,*) 'This is a shareable image to link against not run'   
          end   
   c   
          subroutine say   
          write(*,*) 'Hi'   
          end   
   $ for lib   
   $ link/share=libshr lib + sys$input/opt   
   symbol_vector=(say=procedure)   
   $   
   $ define/nolog libshr sys$disk:[]libshr   
   $ for prg   
   $ link prg + sys$input/opt   
   libshr/share   
   $   
   $ run prg   
   Hi   
   $ run libshr   
   This is a shareable image to link against not run   
      
   So I think the conclusion must be that one should   
   not think the traditional grouping:   
   * executable image   
   * shareable image   
   but instead:   
   * image with transfer address   
   * image with symbol vector   
   * image with both transfer address and symbol vector   
      
   :-)   
      
   I believe that is rare for native code.   
      
   But common for non-native code.   
      
   $ type prg.py   
   import lib   
      
   if __name__ == '__main__':   
        lib.say()   
      
   $ type lib.py   
   def say():   
        print('Hi')   
      
   if __name__ == '__main__':   
        print('This is a library not a program')   
      
   $ python prg.py   
   Hi   
   $ python lib.py   
   This is a library not a program   
   $ type Prg.java   
   public class Prg {   
        public static void main(String[] args) {   
            Lib.say();   
        }   
   }   
   $ type Lib.java   
   public class Lib {   
        public static void say() {   
            System.out.println("Hi");   
        }   
        public static void main(String[] args) throws Exception {   
            System.out.println("This is a library not a program");   
        }   
   }   
   $ javac Prg.java Lib.java   
   $ java Prg   
   Hi   
   $ java Lib   
   This is a library not a program   
      
   Arne   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca