April 23rd 2010 08:14 pm

Java/C++ polyglot

Today I discovered Java’s “inline C++” keyword, //\u000a/*, which makes a Java/C++ polyglot pretty easy:


//\u000a/*
#include <iostream>

#define private
#define public
#define static
#define void int
struct {
  std::ostream &println(const char *c) {
    return std::cout << c < < std::endl;
  }
} out;

//*/
/*\u002a/
import static java.lang.System.out;

public class Polyglot {
//*/
  public static void main(/*\u002a/String[] args//*/
      ) {
    out.println("Hello from whatever language this is!");
  }

/*\u002a/
}
// */

Eclipse deals.. okay. The red-underlining in the commented sections is for the spelling. <3

1 Comment »

One Response to “Java/C++ polyglot”

  1. Anonymous on 30 Jul 2010 at 2:23 pm #

    Help! trying to update my Linux kernel but can’t find the ‘Window’s Update’ icon or the start menu.

Trackback URI | Comments RSS

Leave a Reply

Anti-Spam Protection by WP-SpamFree

« | »