The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Translating C pointers to Java

Posted by Lutz Ihlenburg on April 20, 2000 at 3:42 AM

Hi all,

with the following attempt to transfer a program I failed. The Java program prints 'null', not 33. Is there a way, which leads to the correct result? But I do not mean programs, which int as return value supplies or which int a into an array of the length one pack. That already occurred to me.
If there is no solution: Why may one make something in Java with arrays, what is forbidden with normal objects?
Best greetings Lutz

/************ C code ************************

int x;

void subprog(int* a)
{
*a = 33;
return;
}

void main(void)
{
subprog(&x);
printf("%d\n", x);
}

************* Faulty Java translation ******/

public class Stupid
{
static Integer x;
static public void a(Integer y)
{
y = new Integer(33);
}
public static void main(String[] args)
{
a(x);
System.out.println(x);
}
}





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us