After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 652310 - Constant string array is not constant in C code
Constant string array is not constant in C code
Status: RESOLVED DUPLICATE of bug 622708
Product: vala
Classification: Core
Component: Arrays
0.12.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2011-06-10 18:16 UTC by Jacques-Pascal Deplaix
Modified: 2018-02-26 09:50 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jacques-Pascal Deplaix 2011-06-10 18:16:56 UTC
When I use a function wich have as C argument:

const gchar**

So in vala code I call this function like this:

func({ "some string" });

But this code cause a gcc & Clang/LLVM warning (for Gtk.AboutDialog.set_authors):

src/about.c:89:56: warning: passing 'gchar **' (aka 'char **') to parameter of
      type 'const gchar **' (aka 'const char **') discards qualifiers in nested
      pointer types
        gtk_about_dialog_set_authors ((GtkAboutDialog*) self, _tmp5_);
                                                              ^~~~~~
In file included from src/about.c:7:
In file included from /usr/include/gtk-2.0/gtk/gtk.h:33:
/usr/include/gtk-2.0/gtk/gtkaboutdialog.h:112:26: note: passing argument to
      parameter 'authors' here
  ...const gchar    **authors);

In C code, a new temporary variable is created, but it's useless !

I tested two ways to fix this:

1) A local constant array
2) A class/global constant array

The fist way produce a gcc & Clang/LLVM error:

src/about.c:63:28: error: initializer element is not a compile-time constant
        static const gchar* a[] = {_tmp0_};

The second way works but it's not optimised ! (use a C static variable)

Note: I use Clang/LLVM for warnings and errors because it's more detailed.
Comment 1 Michael 'Mickey' Lauer 2018-02-26 09:50:25 UTC

*** This bug has been marked as a duplicate of bug 622708 ***