swig -go
Working through the Go SWIG tutorial :
Using two files: example.c and example.i
/* File : example.c */
#include <time.h>
double My_variable = 3.0;
int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}
int my_mod(int x, int y) {
return (x%y);
}
char *get_time()
{
time_t ltime;
time(<ime);
return ctime(<ime);
}
%module example
%{
/* Put header files here or function declarations like below */
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
%}
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
________________________________________________________
% gcc -c -fpic example.c
% gcc -c -fpic example_wrap.c
% gcc -shared example.o example_wrap.o -o example.so
% 6g example.go
% 6c example_gc.c
example_gc.c:14 6c: No such file or directory: runtime.h
Using two files: example.c and example.i
/* File : example.c */
#include <time.h>
double My_variable = 3.0;
int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}
int my_mod(int x, int y) {
return (x%y);
}
char *get_time()
{
time_t ltime;
time(<ime);
return ctime(<ime);
}
______________________________________________
/* example.i */%module example
%{
/* Put header files here or function declarations like below */
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
%}
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
________________________________________________________
Then, according to the instructions in http://www.swig.org/Doc2.0/Go.html#Go
% swig -go example.i% gcc -c -fpic example.c
% gcc -c -fpic example_wrap.c
% gcc -shared example.o example_wrap.o -o example.so
% 6g example.go
% 6c example_gc.c
example_gc.c:14 6c: No such file or directory: runtime.h
After reading golang-nuts thread:
% 6c -I ${GOROOT}/pkg/${GOOS}_${GOARCH}
-D_64BIT example_gc.c
This works.
what does an Amazon EC2 instance cost per month?
Output:
Small instance:
variable cost per month: 21.84
fixed cost per month: 9.72
Monthly small: 31.56
Large instance:
vairiable cost per month: 87.36
fixed cost per month: 38.89
Monthly Large: 126.25
Playing with Strings
Received learninggo yesterday and playing around with formatting strings.
Output:
Using the string: "Hello this is Greg" does this have the prefix:He?: true
and how many non-overlapping occurrances of "is?": 2
Hello 23
Hello 23
-23 int
Go-syntax representation of the value:&main.T{a:7, b:-2.35, c:"abc"}
Go-syntax representation of the type of the value:*main.T
Type:[]string Go-rep of the val:[]string{"Hello", "this", "is", "Greg"}
Hello
this
is
Greg
Also started embedding source on this blog using bitbucket's "embed" script after pushing the source code files from my local computer. I'm using gofmt, and after seeing how long my code is, I'm going to look and see if there's an option to wrap lines.
Output:
Using the string: "Hello this is Greg" does this have the prefix:He?: true
and how many non-overlapping occurrances of "is?": 2
Hello 23
Hello 23
-23 int
Go-syntax representation of the value:&main.T{a:7, b:-2.35, c:"abc"}
Go-syntax representation of the type of the value:*main.T
Type:[]string Go-rep of the val:[]string{"Hello", "this", "is", "Greg"}
Hello
this
is
Greg
Also started embedding source on this blog using bitbucket's "embed" script after pushing the source code files from my local computer. I'm using gofmt, and after seeing how long my code is, I'm going to look and see if there's an option to wrap lines.
Subscribe to:
Posts (Atom)