[Assorted-commits] SF.net SVN: assorted: [835] sandbox/trunk/src
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-06-02 00:17:03
|
Revision: 835 http://assorted.svn.sourceforge.net/assorted/?rev=835&view=rev Author: yangzhang Date: 2008-06-01 17:16:49 -0700 (Sun, 01 Jun 2008) Log Message: ----------- added a bunch of sandbox stuff Added Paths: ----------- sandbox/trunk/src/c/euclid.c sandbox/trunk/src/c/hello.c sandbox/trunk/src/cc/hello.cc sandbox/trunk/src/cc/privacy.cc sandbox/trunk/src/java/ClassLoadingThread.java Added: sandbox/trunk/src/c/euclid.c =================================================================== --- sandbox/trunk/src/c/euclid.c (rev 0) +++ sandbox/trunk/src/c/euclid.c 2008-06-02 00:16:49 UTC (rev 835) @@ -0,0 +1,3 @@ +#include <stdio.h> +int gcd(int a, int b) { return ( b != 0 ? gcd(b, a % b) : a ); } +int main() { printf("%d %d\n", gcd(6,4), gcd(4,6)); return 0; } Added: sandbox/trunk/src/c/hello.c =================================================================== --- sandbox/trunk/src/c/hello.c (rev 0) +++ sandbox/trunk/src/c/hello.c 2008-06-02 00:16:49 UTC (rev 835) @@ -0,0 +1,8 @@ +#include <stdio.h> + +int +main() +{ + printf("hello, world!\n"); + return 0; +} Added: sandbox/trunk/src/cc/hello.cc =================================================================== --- sandbox/trunk/src/cc/hello.cc (rev 0) +++ sandbox/trunk/src/cc/hello.cc 2008-06-02 00:16:49 UTC (rev 835) @@ -0,0 +1,15 @@ +// A simple hello world application. +// +// Try compiling this on a 64-bit machine for a 32-bit target with `g++ -m32 +// hello.cc`. + +#include <iostream> + +using namespace std; + +int +main() +{ + cout << "hello, world!" << endl; + return 0; +} Added: sandbox/trunk/src/cc/privacy.cc =================================================================== --- sandbox/trunk/src/cc/privacy.cc (rev 0) +++ sandbox/trunk/src/cc/privacy.cc 2008-06-02 00:16:49 UTC (rev 835) @@ -0,0 +1,29 @@ +/** + * Is there any way at all to allow another class (such as testing) to peer + * into the protected state of an instance of c (that isn't `this`)? + * + * Probably not, since that would be asking for nothing short of + */ + +#include <stdlib.h> + +#define check(x) if (!(x)) { exit(1); } + +class c { + public: c() : x(0) {} + protected: int x; +}; + +class tester : public c { + public: + void test(c& c) { + if (c.x != 0) exit(1); + } +}; + +int main() { + c c; + tester t; + t.test(c); + return 0; +} Added: sandbox/trunk/src/java/ClassLoadingThread.java =================================================================== --- sandbox/trunk/src/java/ClassLoadingThread.java (rev 0) +++ sandbox/trunk/src/java/ClassLoadingThread.java 2008-06-02 00:16:49 UTC (rev 835) @@ -0,0 +1,27 @@ +// From http://www.drmaciver.com/2008/04/object-main-extends-application-considered-harmful/: +// +// Because the initialization of the Main$ class depends on the construction of +// the Main object, Main$ will not be fully initialized until the constructor +// has exited. The JVM semantics guarantee that class loading is single +// threaded and that other threads cannot access the class until it has +// finished loading. Hence the observed problem. +// +// However, I (Yang) couldn't repro this! XXX + +public class ClassLoadingThread { + static { + System.out.println("hello"); + final ClassLoadingThread x = new ClassLoadingThread(); + Runnable r = new Runnable() { + public void run() { + synchronized(x) { x.notify(); } + } + }; + new Thread(r).start(); + try { synchronized(x) { x.wait(); } } + catch (Exception ex) { throw new RuntimeException(ex); } + } + public static void main(String[] args) { + System.out.println("world"); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |