People,


truby2c.rb:

#!/usr/bin/ruby

require 'rubygems'
require 'ruby_to_ansi_c'

class MyTest
   def arr_iterate
     tstarr = [ 'this is the first line', 'this is the second line', 
'last line' ]

     tstarr.each { |line|
         puts line
     }
   end

   def main
     arr_iterate
     return 0
   end
end

result = RubyToAnsiC.translate_all_of MyTest
puts result


gives C output:

void arr_iterate();
long main();

void
arr_iterate() {
str * tstarr;
tstarr = (str) malloc(sizeof(str) * 3);
tstarr[0] = "this is the first line";
tstarr[1] = "this is the second line";
tstarr[2] = "last line";
unsigned long index_line;
for (index_line = 0; tstarr[index_line] != NULL; ++index_line) {
str line = tstarr[index_line];
puts(line);
}
}

long
main() {
arr_iterate();
return 0;
}


compiling with gcc gives:

truby2c.c: In function 'arr_iterate':
truby2c.c:9: error: 'str' undeclared (first use in this function)
truby2c.c:9: error: (Each undeclared identifier is reported only once
truby2c.c:9: error: for each function it appears in.)
truby2c.c:9: error: 'tstarr' undeclared (first use in this function)
truby2c.c:10: error: expected ';' before 'malloc'
truby2c.c:16: error: expected ';' before 'line'
truby2c.c:17: error: 'line' undeclared (first use in this function)
truby2c.c: In function 'main':
truby2c.c:22: warning: return type of 'main' is not 'int'


- seems like some fundamental problems with such a little program?

Thanks,

Phil.
-- 
Philip Rhoades

Pricom Pty Limited  (ACN 003 252 275  ABN 91 003 252 275)
GPO Box 3411
Sydney NSW	2001
Australia
E-mail:  phil / pricom.com.au