代码之家  ›  专栏  ›  技术社区  ›  gavr

收到一堆GCC警告

  •  1
  • gavr  · 技术社区  · 6 年前

    在编译时,一个简单的程序可以发现一个字符串中是否有相同的字母,从而产生一系列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);
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   Michael Gratton    6 年前

    this answer 你没有做错什么,只是C编译器没有Vala编译器那么多的信息,因此抱怨Valac生成的一些C代码。