|
-
August 4th, 2009, 02:31 AM
#1
conversion from c to java
Hi,
I'm working in conversion of code from c to java, what will be the equivelent for the following code.
typedef struct bit_file {
FILE *file;
unsigned char mask;
int rack;
int pacifier_counter;
} BIT_FILE;
void OutputCode( output_file, code )
BIT_FILE *output_file;
int code;
{
int top_of_range;
int abs_code;
int bit_count;
if ( code == 0 ) {
OutputRunLength++;
return;
}
if ( OutputRunLength != 0 ) {
while ( OutputRunLength > 0 ) {
OutputBits( output_file, 0L, 2 );
if ( OutputRunLength <= 16 ) {
OutputBits( output_file,
(unsigned long) ( OutputRunLength - 1 ), 4 );
OutputRunLength = 0;
} else {
OutputBits( output_file, 15L, 4 );
OutputRunLength -= 16;
}
}
}
if ( code < 0 )
abs_code = -code;
else
abs_code = code;
top_of_range = 1;
bit_count = 1;
while ( abs_code > top_of_range ) {
bit_count++;
top_of_range = ( ( top_of_range + 1 ) * 2 ) - 1;
}
if ( bit_count < 3 )
OutputBits( output_file, (unsigned long) ( bit_count + 1 ), 3 );
else
OutputBits( output_file, (unsigned long) ( bit_count + 5 ), 4 );
if ( code > 0 )
OutputBits( output_file, (unsigned long) code, bit_count );
else
OutputBits( output_file, (unsigned long) ( code + top_of_range ),
bit_count );
}
void OutputBits( bit_file, code, count )
BIT_FILE *bit_file;
unsigned long code;
int count;
{
unsigned long mask;
mask = 1L << ( count - 1 );
while ( mask != 0) {
if ( mask & code )
bit_file->rack |= bit_file->mask;
bit_file->mask >>= 1;
if ( bit_file->mask == 0 ) {
if ( putc( bit_file->rack, bit_file->file ) != bit_file->rack )
printf( "Fatal error in OutputBit!\n" );
else if ( ( bit_file->pacifier_counter++ & PACIFIER_COUNT ) == 0 )
putc( '.', stdout );
bit_file->rack = 0;
bit_file->mask = 0x80;
}
mask >>= 1;
}
}
-
August 4th, 2009, 03:21 AM
#2
Re: conversion from c to java
r_punidha, I don't believe there is a free C-to-Java translation service here.
If you show us what you've got so far, and what you're stuck on, we may be able to help you with it.
Reinventing the wheel is a process...
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.
-
August 4th, 2009, 07:18 PM
#3
Re: conversion from c to java
That's not valid C code.
e.g., the following makes no sense at all - since when can you define variables between the method header and the opening brace of the method?
[code]
void OutputCode( output_file, code )
BIT_FILE *output_file;
int code;
{
...
[/code/
Where did you get this C code?
-
August 5th, 2009, 12:45 PM
#4
Re: conversion from c to java
 Originally Posted by David Anton
since when can you define variables between the method header and the opening brace of the method?
Since C was designed (around 1972). That is actually the declaration of the formal parameters passed to the method, not the definition of variables. I could agree with you that it is a bit old fashion, but it is still perfectly valid.
-
August 5th, 2009, 05:44 PM
#5
Re: conversion from c to java
Which compilers allow it?
I do most of my testing in VC++ and it doesn't compile there.
-
August 5th, 2009, 06:27 PM
#6
Re: conversion from c to java
Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)
//always looking for job opportunities in AU/NZ/US/CA/Europe :P
willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));
USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!
-
August 8th, 2009, 06:36 PM
#7
Re: conversion from c to java
 Originally Posted by r_punidha
Hi,
I'm working in conversion of code from c to java, what will be the equivelent for the following code.
Just an idea of a different approach. Java has an interface called JNI. It allows you to call code written in other languages, like C, from Java.
In your case it may be easier to collect a library of C code, and then use it from Java via JNI.
Say you have millions of lines of C code. Instead of turning them into Java you make a C library out of them and call them from Java instead.
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
|