Entry (main) method inside a class?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Fri Mar 16 16:39:16 PDT 2007


Benji Smith wrote:
> Frits van Bommel wrote:
>> Dejan Lekic wrote:
>>> Is there particular reason why we are not able to have entry (main) 
>>> method inside a class, like is possible in JAVA for an example?
>>> Even though I am not a big JAVA fan, I must say I like that 
>>> feature... :)
>>
[snip]
> It can be convenient to package up a JAR file with multiple executable 
> classes. Then you can run multiple different applications with the same 
> binary just by passing a different app name on the commandline.
> 
> It doesn't really apply to D, though. Without a runtime classloader, it 
> doesn't make any sense to have a single EXE with multiple entry points.

I can think of several programs on my system that change their behavior 
depending on the value of argv[0]...
Though perhaps not multiple entry points, that check + symlinks probably 
gets pretty close for compiled programs.

Or you could use dynamic libraries (OS-native or DDL) together with 
small executables that load those libraries, saving you from having 
multiple versions of the shared code.

Combining the techniques, I could even see a program that just loads 
argv[0] ~ ".so", looks up "void run()" in it and calls it. Then even the 
loader code is shared...

However, the first technique doesn't work on Windows because it lacks 
symlinks (to files, at least).
Though a few batch files that all run the same executable, each with a 
different --version=whatever (or some such) would look similar to the user.



More information about the Digitalmars-d mailing list