|
-
December 29th, 2009, 10:19 PM
#1
Converting C functions into Java
Hey guys!
I need help translating an old C program into a Java program. I've done most of it using basic message boxes, but the thing is, I can't figure out how to make the Java equivalent of user-defined functions in C properly. Can you guys give me an example?
Thanks!
-
December 30th, 2009, 07:16 AM
#2
Re: Converting C functions into Java
Please give an example of what you mean by a 'user-defined' function.
To arrive at the simple is difficult...
R. Elisha
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
December 30th, 2009, 08:50 AM
#3
Re: Converting C functions into Java
How have you done most of it without being able to convert your 'user defined functions' into methods? There are two types of functions in C: library and user defined. In Java we have the same thing, but we just don't call them user defined.
Our library functions come from the SDK. Functions like: System.out.println(), or Math.pow().
User defined are just that: written by the user. Only we don't call them functions, we call them methods:
public void doFoo() {
//do something foo
}
They work very similar to C style functions, just don't try to get crazy and try to convert something "protected abstract virtual base pure virtual private", because we just don't have anything like that.
Starts with the access type modifier: public, private, protected. Then goes to the return type, then name of the function followed by the paramater list in the (). Pretty much the same as C. There are a few differences you will find, but you'll have to hash those out as they come, I don't know them off of the top of my head.
-
December 30th, 2009, 10:52 AM
#4
Re: Converting C functions into Java
 Originally Posted by ProgramThis
How have you done most of it without being able to convert your 'user defined functions' into methods? There are two types of functions in C: library and user defined. In Java we have the same thing, but we just don't call them user defined.
Our library functions come from the SDK. Functions like: System.out.println(), or Math.pow().
User defined are just that: written by the user. Only we don't call them functions, we call them methods:
public void doFoo() {
//do something foo
}
They work very similar to C style functions, just don't try to get crazy and try to convert something "protected abstract virtual base pure virtual private", because we just don't have anything like that.
Starts with the access type modifier: public, private, protected. Then goes to the return type, then name of the function followed by the paramater list in the (). Pretty much the same as C. There are a few differences you will find, but you'll have to hash those out as they come, I don't know them off of the top of my head.
C does not have any OO constructs such as class, public, private, protected, virtual, etc.
As for conversion, who is good with Java and C it will be trivial. That doesn't look to be case here. There's no general rule, it is on implementer's discretion. Things to look at are certainly difference in standard library calls ( System.out.println vs printf for example) and lack of pointers and structs in Java.
-
December 30th, 2009, 07:37 PM
#5
Re: Converting C functions into Java
Post an example of something you need converted.
Maybe a conversion of one small sample will get you started on the right track.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|