1

この問題を示す短いプログラムを次に示します。

void main(string[] args)
{
    unichar c = 'a';
    string str_from_to_string = c.to_string(); // Warning
    stdout.printf("Converted by unichar.to_string: \"%s\"\n", str_from_to_string);
}

これにより、同じ警告も発生します。

void main(string[] args)
{
    unichar c = 'a';
    string str_from_template = @"$c"; // Warning
    stdout.printf("Converted by string template: \"%s\"\n", str_from_template);
}

これは私が得る警告です:

/home/mpiroc/Desktop/unicode_to_string/unicode_to_string.vala.c: In function ‘g_unichar_to_string’:
/home/mpiroc/Desktop/unicode_to_string/unicode_to_string.vala.c:26:2: warning: passing argument 2 of ‘g_unichar_to_utf8’ discards ‘const’ qualifier from pointer target type [enabled by default]
/usr/include/glib-2.0/glib/gunicode.h:684:11: note: expected ‘gchar *’ but argument is of type ‘const gchar *’

そして、警告に記載されている生成されたcコードは次のとおりです。

 18 static gchar* g_unichar_to_string (gunichar self) {
 19     gchar* result = NULL;
 20     gchar* _tmp0_ = NULL;
 21     gchar* str;
 22     const gchar* _tmp1_;
 23     _tmp0_ = g_new0 (gchar, 7);
 24     str = (gchar*) _tmp0_;
 25     _tmp1_ = str;
 26     g_unichar_to_utf8 (self, _tmp1_);
 27     result = str;
 28     return result;
 29 }

_tmp_おそらくマークされるべきではないように思えますが、これは私が直接書いたのではなく、constによって生成されました。valac私は何か間違ったことをしていますか?それともバグvalacですか?コードは期待どおりに機能しますが、可能な場合は警告を回避するようにしています。

4

2 に答える 2

1

--disable-warnings コマンドライン オプションを追加

IIRC Vala コンパイラは、 --disable-warnigs コマンドライン オプションも使用できます。

編集:

gcc コマンドライン オプション

申し訳ありませんが、Valac はトランスパイラであるため、valac --ccode が出力されたら、gcc または別のコンパイラを実行する必要があります。

$ valac --ccode unicode_to_string.vala
$ gcc -o unicode_to_string -w unicode_to_string.c `pkg-config --libs --cflags gobject-2.0`
于 2012-05-19T06:25:05.753 に答える
1

Vala コンパイラは一時変数を作成しませんconstconst-nessに関する警告は無視しても問題ありません。

于 2012-05-19T00:51:06.340 に答える