- C言語なら俺に聞け 152
671 :デフォルトの名無しさん (ワッチョイ 4f25-WSqd)[]:2019/07/23(火) 03:25:09.81 ID:/ZO3BTO70 - gchar **command = (gchar *[]){"./Hello.exe","World",NULL};
を gcc6 で compile すると以下の2種類の warning が出ます。 warning: ISO c++11 does not allow conversion from string literal to 'gchar *' (aka 'char *') [-Wwritable-strings] warning: pointer is initialized by a temporary array, which will be destroyed at the end of the full-expression [-Waddress-of-array-temporary] どう書くのが正解なのでしょうか? 教えてください。最後の NULL がなければ、 gchar **command = (gchar **)((char [][20]){"./Hello.exe","World"}); で良いと思うのですが、最後の NULL も必要です。よろしくお願いします。
|
- C言語なら俺に聞け 152
680 :671 (ワッチョイ 4f25-WSqd)[]:2019/07/23(火) 11:49:30.09 ID:/ZO3BTO70 - >>673
>char * const command[3] = {"./Hello.exe","World"}; ありがとうございます。これでも1つめの warning "does not allow conv..." は出ました。皆さんの所では出ませんか? それと、 command はどうしても char ** 型である必要があります。 仮想端末で何かを実行させる関数 vte_terminal_spawn_async() に与えるためです。 https://developer.gnome.org/vte/unstable/VteTerminal.html#vte-terminal-spawn-async 引き続きアドバイスをお願いします。
|
- C言語なら俺に聞け 152
682 :671 (ワッチョイ 4f25-WSqd)[]:2019/07/23(火) 12:04:01.45 ID:/ZO3BTO70 - >>672
ありがとうございます。具体的にはどうしたら良いでしょうか? char list[2][20] = {"./Hello.exe","World"}; gchar **command = (gchar **){ (char *)list[0], (char *)list[1], NULL}; だと、↓のエラーになります。 error: function-style cast to a builtin type can only take one argument 正しいやり方をお願いします。 うーむ。どうしたものか。 gchar ** 型をどうやって作るのかさっぱり分からない。。。 ダブルポインタがよく分かってない。もう warning は放っておくしかないのかな?
|
- C言語なら俺に聞け 152
684 :671 (ワッチョイ 4f25-WSqd)[]:2019/07/23(火) 12:21:12.41 ID:/ZO3BTO70 - >>672
gchar list1[][20] = {"../Exe/H2O.exe","World"}; gchar *list2[] = {(gchar *)list1[0], (gchar *)list1[1], NULL}; gchar **command = (gchar **)list2; いろいろ試したところ、↑だと warning でなくなりました。意図されたのはコレでしょうか?コレで良いでしょうか?
|
- C言語なら俺に聞け 152
687 :671 (ワッチョイ 4f25-WSqd)[]:2019/07/23(火) 12:24:46.80 ID:/ZO3BTO70 - >>683
なんかおかしいですよね。 でも Makefile に書いていいて実際に compile に使っているのは間違いなく gcc6 です。 warning が g++6 と共通なのですかね?
|
- C言語なら俺に聞け 152
691 :671 (ワッチョイ 4f25-WSqd)[]:2019/07/23(火) 13:18:08.85 ID:/ZO3BTO70 - >>688
ありがとうございます。スマートですね。参考にします。 gchar は char の別名です。すみません。
|
- C言語なら俺に聞け 152
692 :671 (ワッチョイ 4f25-WSqd)[]:2019/07/23(火) 13:24:51.89 ID:/ZO3BTO70 - >>683
Makefile には gcc6 と書いてあるのですが、出力をみると c++ でコンパイルしていました。。。 今気づきました。 -std=c++11 もつけてある。 Cのソースを c++ でコンパイルするとマズいですか?今のところ何も問題はないです。
|