很不爽,用了一周时间在Linux就学会了一门新的编程语言vala叽哩哇啦,学一个新语言咋就这么容易捏
Vala 是使用类似 C# 的语法,应该比用 C 写轻松的多。Vala 编译的时候,会把 Vala 程序编译成 C 代码,然后再使用 C 编译器编译成本机代码,我最近觉得这种编译方式很好,因为现在而言,几乎任何一个系统,不论是 PC 的,还智能手机,抑或嵌入式设备,总会至少提供一个 C 的编译器,那么把程序先编译成 C 就等于在这些系统上都可以运行了。
代码如下:
//别看错了哦,这可不是C#,这是一个新的语言叫哇啦
int main (string[] args) {
// Output the number of arguments
stdout.printf ("%d command line argument(s):\n", args.length);
// Enumerate all command line arguments
foreach (string arg in args) {
stdout.printf ("%s\n", arg);
}
// Exit code (0: success, 1: failure)
return 0;
}
直接编译成纯C语言代码
代码如下:
/* main.c generated by valac 0.14.0, the Vala compiler
* generated from main.vala, do not modify */
/*别看错了哦,这可不是C#,这是一个新的语言叫哇啦*/
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define _g_free0(var) (var = (g_free (var), NULL))
gint _vala_main (gchar** args, int args_length1);
gint _vala_main (gchar** args, int args_length1) {
gint result = 0;
FILE* _tmp0_;
gchar** _tmp1_;
gint _tmp1__length1;
gchar** _tmp2_;
gint _tmp2__length1;
#line 5 "/media/disk i_/working/vala/test1/test1/main.vala"
_tmp0_ = stdout;
#line 5 "/media/disk i_/working/vala/test1/test1/main.vala"
_tmp1_ = args;
#line 5 "/media/disk i_/working/vala/test1/test1/main.vala"
_tmp1__length1 = args_length1;
#line 5 "/media/disk i_/working/vala/test1/test1/main.vala"
fprintf (_tmp0_, "%d command line argument(s):\n", _tmp1__length1);
#line 8 "/media/disk i_/working/vala/test1/test1/main.vala"
_tmp2_ = args;
#line 8 "/media/disk i_/working/vala/test1/test1/main.vala"
_tmp2__length1 = args_length1;
#line 39 "main.c"
{
gchar** arg_collection = NULL;
gint arg_collection_length1 = 0;
gint _arg_collection_size_ = 0;
gint arg_it = 0;
#line 8 "/media/disk i_/working/vala/test1/test1/main.vala"
arg_collection = _tmp2_;
#line 8 "/media/disk i_/working/vala/test1/test1/main.vala"
arg_collection_length1 = _tmp2__length1;
#line 8 "/media/disk i_/working/vala/test1/test1/main.vala"
for (arg_it = 0; arg_it < _tmp2__length1; arg_it = arg_it + 1) {
#line 51 "main.c"
gchar* _tmp3_;
gchar* arg = NULL;
#line 8 "/media/disk i_/working/vala/test1/test1/main.vala"
_tmp3_ = g_strdup (arg_collection[arg_it]);
#line 8 "/media/disk i_/working/vala/test1/test1/main.vala"
arg = _tmp3_;
#line 58 "main.c"
{
FILE* _tmp4_;
const gchar* _tmp5_;
#line 9 "/media/disk i_/working/vala/test1/test1/main.vala"
_tmp4_ = stdout;
#line 9 "/media/disk i_/working/vala/test1/test1/main.vala"
_tmp5_ = arg;
#line 9 "/media/disk i_/working/vala/test1/test1/main.vala"
fprintf (_tmp4_, "%s\n", _tmp5_);
#line 8 "/media/disk i_/working/vala/test1/test1/main.vala"
_g_free0 (arg);
#line 70 "main.c"
}
}
}
#line 13 "/media/disk i_/working/vala/test1/test1/main.vala"
result = 0;
#line 13 "/media/disk i_/working/vala/test1/test1/main.vala"
return result;
#line 78 "main.c"
}
int main (int argc, char ** argv) {
#line 2 "/media/disk i_/working/vala/test1/test1/main.vala"
g_type_init ();
#line 2 "/media/disk i_/working/vala/test1/test1/main.vala"
return _vala_main (argv, argc);