Empty program

From Rosetta Code
Task
Empty program
You are encouraged to solve this task according to the task description, using any language you may know.

In this task, the goal is to create the simplest possible program that is still considered "correct."

Programming Languages

Ada

Compiler: GCC 4.1.2

  procedure Empty is begin null; end;

AppleScript

An empty .scpt file is considered the smallest runnable code, but the following would also be acceptable.

return

AWK

Interpreter: AWK Compilers: awka awkcc (untested)

  BEGIN{}

BASIC

Interpreter: QBASIC

  END

C

Compiler: GCC 4.0.3

int main (int argc, char *argv[])
{
  return 0;
}


Works also:

int main ()
{
  return 0;
}

C#

Compiler: Visual C# 2005

static class Program
{
    static void Main(string[] args)
    {
    }
}

C++

Compiler: GCC 4.0.3

int main ( int /*argc*/, char * * /*argv*/ ) 
{
 // Unused arguments should not be named
 // There are variations:
 // 1: main may explicitly return a value
 //    (other non-void-returning C++ functions must do so,
 //    but there's a special exception for main that falling off it
 //    without an explicit return is equivalent to a "return 0;" at
 //    the end of the main function)
 // 2: The arguments may be omitted entirely
}

D

Compiler: DMD 1.002

void main() {
}

Haskell

Standard: Haskell98

module Main where
main :: IO ()
main = return ()

Java

Compiler: Sun javac, JDK 1.5.0 and up

public class EmptyMainClass {
    public static void main(String[] args) {
    }
}
public class EmptyApplet extends java.applet.Applet {
    @Override public void init() {
    }
}

Compiler: Sun javac, JDK 1.0 and Up

public class EmptyMainClass {
    public static void main(String[] args) {
    }
}
public class EmptyApplet extends java.applet.Applet {
    public void init() {
    }
}

@Override - Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message. It's present from JDK 5.0 (1.5.0) and up.

Actually this is not strictly correct. The smallest possible correct program in Java is an empty source file.

LISP

 ()

This is also the shortest LISP program that prints its own source upon execution.

OCaml

Interpreter/Compiler: Ocaml 3.09

;;

Actually, the smallest possible correct program in OCaml is an empty source file.

Pascal

Compiler: Borland Pascal

program ProgramName;

begin
end.

Perl

Interpreter: Perl 5.8.8

#!/usr/bin/perl


Is this correct? As far as I am aware, that is a shell statement, not perl code. It instructs the shell as to where to find the interpreter to use.

#!/usr/bin/ksh

Would use the korn shell. etc..?

PHP

<?php ?>

PL/SQL

BEGIN
  NULL;
END;

PostScript

In general, the first 4 characters of the file have to be

%!PS

If a particular version of the PS interpreter is needed, this would be included right there:

%!PS-2.0
% ...or...
%!PS-3.0
% etc

Python

Interpreter: Python 2.4.3

For Python an empty text file is an empty program.

#!/usr/bin/env python

Actually that just tells the shell to run the python interpreter. Try this:

pass

Ruby

Interpreter: Ruby 1.8.5

#!/usr/bin/env ruby

Starting an Interactive RuBy shell

 irb

UNIX Shell

Interpreter: Debian Almquist SHell

#!/bin/sh

Interpreter: Bourne Again SHell

#!/bin/bash

Visual Basic .NET

Compiler: Visual Basic .NET 2005

Module General
    Sub Main()
    End Sub
End Module

xTalk

Interpreter: HyperCard

on startup
  
end startup

eSQL

CREATE COMPUTE MODULE ESQL_Compute
 CREATE FUNCTION Main() RETURNS BOOLEAN
 BEGIN
   RETURN TRUE;
 END;
END MODULE;

Markup Languages

LaTeX

Compiler: pdfeTeXk, Version 3.141592-1.30.4-2.2 (Web2C 7.5.5), LaTeX2e (2003/12/01)

\documentclass{article}
\begin{document}
\end{document}