收到一堆 GCC 警告
Getting a bunch of GCC warnings
一个简单的程序,用于查找字符串中是否有相同的字母,编译时会产生一堆 C 警告。我究竟做错了什么? (程序运行正常)
using Gee;
void main(string[] args) {
var s="♜♝♞♟♠♞";
unichar c;
var records = new HashMap<unichar, bool> ();
for (int i = 0; s.get_next_char (ref i, out c);) {
stdout.printf (@"$i, $c\t");
if (records[c]==true){
stdout.printf("буква найдена: true\n");break;
}else{
records[c]=true;stdout.printf("буква не найдена: false\n");
}
}
}
gavr@archlabs ~/D/c/V/T / Task51> vala console.vala --pkg gee-0.8
/tmp / console.vala.BF33WZ.c: in the function " g_unichar_to_string»:
/tmp / console.vala.BF33WZ.c: 65: 27: warning: passing argument 2 " g_unichar_to_utf8 "cancels the" const " qualifier of the type [- Wdiscarded-qualifiers]
g_unichar_to_utf8 (self, _tmp1_);
^~~~~~
In file included from/usr/include/glib-2.0/glib / gstring.h: 33,
from / usr/include/glib-2.0/glib / giochannel.h: 34,
from / usr/include/glib-2.0 / glib.h: 54,
from / tmp / console.vala.BF33WZ.c: 6.:
/usr/include/glib-2.0/glib / gunicode.h:844:42: note: type "gchar *" {aka "char*"} was expected, but the argument is of type "const gchar *" {aka " const char *»}
gchar *outbuf);
Per this answer,你没有做错任何事,只是 C 编译器没有像 vala 编译器那样多的信息,因此抱怨 valac 生成的一些 C 代码.
一个简单的程序,用于查找字符串中是否有相同的字母,编译时会产生一堆 C 警告。我究竟做错了什么? (程序运行正常)
using Gee;
void main(string[] args) {
var s="♜♝♞♟♠♞";
unichar c;
var records = new HashMap<unichar, bool> ();
for (int i = 0; s.get_next_char (ref i, out c);) {
stdout.printf (@"$i, $c\t");
if (records[c]==true){
stdout.printf("буква найдена: true\n");break;
}else{
records[c]=true;stdout.printf("буква не найдена: false\n");
}
}
}
gavr@archlabs ~/D/c/V/T / Task51> vala console.vala --pkg gee-0.8
/tmp / console.vala.BF33WZ.c: in the function " g_unichar_to_string»:
/tmp / console.vala.BF33WZ.c: 65: 27: warning: passing argument 2 " g_unichar_to_utf8 "cancels the" const " qualifier of the type [- Wdiscarded-qualifiers]
g_unichar_to_utf8 (self, _tmp1_);
^~~~~~
In file included from/usr/include/glib-2.0/glib / gstring.h: 33,
from / usr/include/glib-2.0/glib / giochannel.h: 34,
from / usr/include/glib-2.0 / glib.h: 54,
from / tmp / console.vala.BF33WZ.c: 6.:
/usr/include/glib-2.0/glib / gunicode.h:844:42: note: type "gchar *" {aka "char*"} was expected, but the argument is of type "const gchar *" {aka " const char *»}
gchar *outbuf);
Per this answer,你没有做错任何事,只是 C 编译器没有像 vala 编译器那样多的信息,因此抱怨 valac 生成的一些 C 代码.