Re: [Vala] Insert code C in Vala
- From: Frederik <scumm_fredo gmx net>
- To: vala-list gnome org
- Subject: Re: [Vala] Insert code C in Vala
- Date: Fri, 20 May 2011 07:47:47 +0200
Hi,
you can't embed C code directly into Vala code, but you can easily
call C functions from Vala by using the "extern" keyword:
-- a.vala ---------------------------------------------------
extern void this_is_a_c_function(int i, double d, string s);
void main() {
print("This is Vala code\n");
this_is_a_c_function(42, 3.14, "test");
}
-- b.c -----------------------------------------------------
#include <stdio.h>
void this_is_a_c_function(int i, double d, const char *s)
{
puts("This is C code");
printf("i: %d, d: %g, s: %s\n", i, d, s);
}
------------------------------------------------------------
$ valac -o test a.vala b.c
$ ./test
This is Vala code
This is C code
i: 42, d: 3.14, s: test
Best regards,
Frederik
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]