Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Sneftel

Polyglot programs...

This topic is 5786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

...by which I mean programs that will compile and execute in TWO or more programming languages, and do similar or identical things. Anyone got any? here's one to start off... use it with C or Perl.
    
#include <stdio.h>

#define sub int

int main();
sub main() {
        printf("Just another %s hacker.\n",2/3?"Perl":"C");
}
    

Don't listen to me. I've had too much coffee. [edited by - sneftel on August 14, 2002 5:33:31 PM]

Share this post


Link to post
Share on other sites
Advertisement
There''s likely to be very little common syntax between different languages. At a guess, the "mostest polyglot" program is likely to be something like:


print "Hello world"


or the extremely useful:


0

which I''m pretty sure will run in Python, Ruby, Perl, Rebol, Lisp and Rexx and several others.

Share this post


Link to post
Share on other sites
Nahh... the trick is to make the programs work differently, but accomplish the same thing, through creatively getting each language to ignore part of the program.

Here's another one, between C++ and HTML:


  //<script language="none">

#include <stdio.h>

#include <string.h>

int main(){char text[14];
strncpy(text,"</script>Hello, World!<script language="+9, 13);//">

printf(text);return 0;}




Don't listen to me. I've had too much coffee.

[edited by - sneftel on August 14, 2002 7:51:28 PM]

[edited by - sneftel on August 14, 2002 7:52:18 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Sneftel
Nahh... the trick is to make the programs work differently, but accomplish the same thing, through creatively getting each language to ignore part of the program.

The problem with that is either two different languages will recognise the same trick as meaning it is to ignore the same code, or the trick used will produce a syntax error.

Share this post


Link to post
Share on other sites
quote:
Original post by Beer Hunter
A zero-length file is both a quine and a polyglot of many different languages.

Ah, but is *no program* a valid program?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!