From: (Jeremy Todd Dilatush)
Date: 1 Aug 1996 16:18:40 GMT
Organization: Swarthmore College, Swarthmore, PA, USA
Newsgroups: alt.hackers.discuss
Subject: Multi-language program hack
Message-ID: <4tqld0$>

So what's doing these days? What happened the old alt.hackers group, which doesn't seem to be showing up at my site anymore. Did it disappear, or is this group a successor to it? One moment it was there on our news server, then it disappeared. Is this global, or is my school's news server just acting crazy?


I just really felt like showing this off... little hack I did yesterday. It's a file "hello.c". It's the "canonical" first C program... also implemented in Perl, Tcl, and shell.. ie:

$ gcc -o hello hello.c
$ ./hello
Hello world!
$ sh hello.c
Hello world!
$ tclsh hello.c
Hello world!
$ perl hello.c
Hello world!
$ perl5 hello.c
Hello world!

It turned out the perl part was the toughest, because it and the shell conflicted in a few places, and because I don't really know perl, and because the only things I could hack up in perl were specific to perl version 4 or 5...

Here's the code:

#define NAME			hello.c
#define DESCRIP 		many languages at once (tcl, perl 4 & 5, sh, C)
#define AUTHOR			Jeremy Dilatush
#define DATE			7/31/96
#define dummy \
eval qq[qq? 2> /dev/null
#if 0
echo 'Hello world!'; exit 0	# shell part
puts "Hello world!"; exit 0

/* C part */

#include <stdio.h>

int main(void)
  printf ("Hello world!\n");
  return 0;

#define dummy2(perl) \
?]; print "Hello world!\n"; exit 0  # perl part

Note that it may not work with all C compilers; gcc handles it fine, and I've made it so at least the IRIX cc handles it. Other C compilers may have trouble.

Essentially it uses these facts:

If I do any more work on this it will be to comment it (not a simple task) and to make the "Hello World!" a single string constant used meaningfully by all the languages.

Good day and good hacking!

Hacker's Wisdom/ Multi-language program hack
Last modified: Mon Aug 30 09:02:39 EDT 1999