[Vala] Unnecessary g_strdup and compile error.
- From: Kentaro NAKAZAWA <kentaro nakazawa nifty com>
- To: vala-list gnome org
- Subject: [Vala] Unnecessary g_strdup and compile error.
- Date: Fri, 31 Dec 2010 04:14:59 +0900
Hello,
(sorry, my English is not so good ;)
I often write the following codes.
----------------------------------------------------------------
void main () {
var home = Environment.get_home_dir ();
print ("%s\n", home);
}
----------------------------------------------------------------
Then, unnecessary g_strdup is generated.
----------------------------------------------------------------
void _vala_main (void) {
const gchar* _tmp0_ = NULL;
gchar* _tmp1_;
gchar* home;
_tmp0_ = g_get_home_dir ();
_tmp1_ = g_strdup (_tmp0_);
home = _tmp1_;
g_print ("%s\n", home);
_g_free0 (home);
}
----------------------------------------------------------------
It is necessary to write a tedious following codes to avoid it.
----------------------------------------------------------------
void main () {
unowned string home = Environment.get_home_dir ();
print ("%s\n", home);
}
----------------------------------------------------------------
Is not unnecessary g_strdup generated without writing a tedious code?
After that, if the following codes are written, it becomes a compile error. (Vala 0.11.2)
----------------------------------------------------------------
void main () {
const string home = Environment.get_home_dir ();
print ("%s\n", home);
}
----------------------------------------------------------------
/home/kentaro/work/VALA/unnecessary_strdup.vala.c: In function '_vala_main':
/home/kentaro/work/VALA/unnecessary_strdup.vala.c:18: error: invalid initializer
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)
Best regards,
--
Kentaro NAKAZAWA (from Japan)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]