• ベストアンサー

C言語のバグの警告文について

こんばんわ。 C++でプログラムを作成中なのですが警告文の意味がわからないので教えていただきたいです。 警告文 SAMPLE.c: 181 : warning: passing argument 4 of fwrite' makes pointer from integer without a cast /usr/include/stdio.h:688: note: expected 'struct FILE * __restrict__' but argument is of type 'int' どうぞよろしくお願いいたします。

質問者が選んだベストアンサー

  • ベストアンサー
  • kmee
  • ベストアンサー率55% (1857/3366)
回答No.1

「C言語のバグ」ではなく、「あなたが作ったプログラムが違うかもしれないけど大丈夫ですか?」という警告です。 メッセージに書いてある通りで 「fwriteの4番目の引数で、ポインタ→整数への変換がキャスト無しの行われてます」 です。 fwriteの引数指定が間違ってませんか?

rikerume01
質問者

お礼

丁寧な解説ありがとうございました。もう一度考え直して見ます。

関連するQ&A

  • Qpopperをインストールできません

    CentOS6.0にqpopper4.0.13をインストールしようとしたのですが、 makeにて下記のようなエラーが出力されます。 どなたかご存知でしたら、ご教授頂けないでしょうか? ---------------- popper.c: In function ‘qpopper’: popper.c:153: error: conflicting types for ‘getline’ /usr/include/stdio.h:673: note: previous declaration of ‘getline’ was here popper.c: In function ‘tgetline’: popper.c:617: 警告: passing argument 1 of ‘getline’ from incompatible pointer type /usr/include/stdio.h:673: note: expected ‘char ** __restrict__’ but argument is of type ‘char *’ popper.c:617: 警告: passing argument 2 of ‘getline’ makes pointer from integer without a cast /usr/include/stdio.h:673: note: expected ‘size_t * __restrict__’ but argument is of type ‘int’ popper.c:617: 警告: passing argument 3 of ‘getline’ from incompatible pointer type /usr/include/stdio.h:673: note: expected ‘struct FILE * __restrict__’ but argument is of type ‘struct POP *’ popper.c:617: 警告: assignment makes pointer from integer without a cast make[1]: *** [popper.o] エラー 1 make[1]: ディレクトリ `/usr/local/src/qpopper4.0.13/popper' から出ます make: *** [popper_server] エラー 2 ------------------- ここにいたるまでの手順です↓ /usr/sbin/useradd -s /dev/null -d /dev/null pop cd /usr/local/src/ tar -xzf qpopper4.0.13.tar.gz cd qpopper4.0.13 ./configure --enable-apop=/etc/pop.auth =--with-popuid=pop make

  • 警告をださずにポインタにnullを渡す方法は?

    こんにちは。 ポインタ型の引数にNULLを渡してやりたいのですが 以下のような警告がでてしまいます。 test.c: In function 'test_': test.c:14: 警告: passing argument 2 of 'test' makes pointer from integer without a cast 問題の箇所は以下のように書いてます。 【test.c】 ~省略~ /** プロトタイプ **/ 7 void aaa(int,int*,int*); ~省略~ 14 aaa(0,NULL,&tv); NULLを渡したい場合、警告をださないように スマートに記述するにはどうしたらいいでしょうか? よろしくお願いします。

  • 関数への構造体の配列の渡し方<c言語初心者>

    こんにちは、関数への構造体の配列の渡し方で理解できない点があるため、質問させていただきます。 以下がスクリプトになります。3人の名前と年齢をinput関数で入力し、それらのデータをoutput関数で出力するのが目的です。 #include <stdio.h> typedef struct{ char name[64]; int age; }property; void input(property *data[]); void output(property *data[]); int main(void){ property data[3]; printf("Input data of three people.\n"); input(&data); output(&data); return 0; } void input(property *data[]){ int i; for(i=0;i<3;i++){ printf("%d banme\n",i+1); printf("name:"); scanf("%s",&data[i]->name); printf(" age:"); scanf("%3d",&data[i]->age); } return; } void output(property *data[]){ int i; for(i=0;i<3;i++){ printf("%d banme\n",i+1); printf("name:%s\n",data[i]->name); printf("age :%3d\n",data[i]->age); } return; } コンパイル時のエラーメッセージは以下のようになりました。(ファイル名はstructure5.c) structure5.c: In function ‘main’: structure5.c:14:2: warning: passing argument 1 of ‘input’ from incompatible pointer type [enabled by default] input(&data); ^ structure5.c:8:6: note: expected ‘struct property **’ but argument is of type ‘struct property (*)[3]’ void input(property *data[]); ^ structure5.c:15:2: warning: passing argument 1 of ‘output’ from incompatible pointer type [enabled by default] output(&data); ^ structure5.c:9:6: note: expected ‘struct property **’ but argument is of type ‘struct property (*)[3]’ void output(property *data[]); ^ structure5.c: In function ‘input’: structure5.c:24:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[64]’ [-Wformat=] scanf("%s",&data[i]->name); ^ 構造体の配列をinput関数やoutput関数に渡すときにエラーが発生しているようなのですが、自分で調べても解決できなかったため、質問させて頂きます。 皆様のお知恵を貸してください。なおプログラミング言語自体初心者のため、できる限りわかりやすいお言葉でご教授願います。よろしくお願い致します。

  • C言語のポインターに関する警告

    line[100]で 「1」が格納されていたら「a」 「2」が格納されていたら「b」 「3」が格納されていたら「c」 とout[100]に代入する関数を作りたいのですが コンパイルすると関数の部分で warning: assignment makes integer from pointer without a cast という警告がでます。 ポインターは使っていないのですが、ポインターに関する警告が出ているようで困っています。 どこが悪いのかまったくわからなくて作業が完全に止まってしまいました。 解決法をおしえてください。お願いします。 /*宣言*/ int=i; /*main関数内のfor文で使用*/ char line[100], out[100]; void change(int); /*関数*/ void change(int i)   {    if(line[i]=='1'){     out[10]="a\0"    }if(line[i]=='2'){     out[10]="b\0";    }if(line[i]=='3'){     out[10]="c\0" } }

  • C言語 どこがコンパイルエラーか解りません。

    いつも大変お世話になっております。 標記の件。 どこがエラーなのか解りません。 2時間くらい、にらめっこが続いています。 どこがエラーなのか教えて下さい。 ご回答のほどよろしくお願い申し上げます。 コード #include <stdio.h> int a = 0; void func(void) { int c = 2; printf("func関数では変数aとcが使えます。¥n”); printf("変数aの値は%dです。\n",a); /*printf("変数bの値は%dです。\n",b);*/ printf("変数cの値は%dです。\n",c); } int main(void) { int b = 1; printf("main関数では変数aとbが使えます。\n"); printf("変数aの値は%dです。\n", a); printf("変数bの値は%dです。\n", b); /*printf("変数cの値は%dです。\n", c); */ func(); return 0; } コンパイルエラー printf("func関数では変数aとcが使えます。¥n”); ^ text10.c:9:8: error: missing terminating " character printf("func関数では変数aとcが使えます。¥n”); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ text10.c:10:34: error: expected ')' before ';' token printf("変数aの値は%dです。\n",a); ^ text10.c:10:1: warning: passing argument 1 of 'printf' makes pointer from integer without a cast [-Wint-conversion] printf("変数aの値は%dです。\n",a); ^~~~~~ In file included from text10.c:1:0: c:\mingw\include\stdio.h:454:38: note: expected 'const char *' but argument is of type 'int' _CRTIMP __cdecl __MINGW_NOTHROW int printf (const char *, ...); ^~~~~~ text10.c:13:1: error: expected ';' before '}' token } どうかよろしくお願いいたします。

  • incompatible pointer type

    incompatible pointer type への対応方法を教えてください。 環境はMicrochipのXC16 Compiler V1.24です。 エラーの出る行は putsUART1("UART1 Test"); エラーは main.c:76:9: warning: passing argument 1 of 'putsUART1' from incompatible pointer type c:\program files (x86)\microchip\xc16\v1.24\bin\bin\../..\support\peripheral_24F/uart.h:396:45: note: expected 'unsigned int *' but argument is of type 'char *' となっています。 uart.hを見ると void __attribute__ ((section (".libperi"))) putsUART1(unsigned int *buffer); とあるので、求められているものと違う形のものを渡してしまっていることは分かります。 ところが、具体的にどう変更すればいいのかわかりません。 プログラムをどのように書き直したらエラーを無くすことが出来ますか? よろしくお願いします。

  • mod_limitipconnのインストールでapxsのコンパイルエラー

    お世話になります。 環境-------------------- Redhat Linux Fedora 5 Apache/2.2.2 ------------------------ mod_limitipconnをインストールしたいのですが、 makeするとapxsのコンパイルエラーが起こりインストールできずにいます。 エラー内容は以下の通りです。 ------------------------ [root@www mod_limitipconn-0.04]# make apxs -c mod_limitipconn.c /usr/lib/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -pthread -I/usr/include/httpd -I/usr/include/apr-1 -I/usr/include/apr-1 -c -o mod_limitipconn.lo mod_limitipconn.c && touch mod_limitipconn.slo mod_limitipconn.c:39: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'limitipconn_module' mod_limitipconn.c:43: error: expected specifier-qualifier-list before 'array_header' mod_limitipconn.c:49: error: expected ')' before '*' token mod_limitipconn.c: In function 'limitipconn_handler': --中略-- mod_limitipconn.c:176: warning: implicit declaration of function 'ap_log_reason' mod_limitipconn.c:178: warning: implicit declaration of function 'ap_table_setn' mod_limitipconn.c: In function 'no_limit_config_cmd': mod_limitipconn.c:208: warning: implicit declaration of function 'ap_push_array' mod_limitipconn.c:208: error: 'limitipconn_dir_config' has no member named 'no_limit' mod_limitipconn.c:208: warning: implicit declaration of function 'ap_pstrdup' mod_limitipconn.c:208: warning: assignment makes pointer from integer without a cast mod_limitipconn.c: In function 'excl_limit_config_cmd': mod_limitipconn.c:218: error: 'limitipconn_dir_config' has no member named 'excl_limit' mod_limitipconn.c:218: warning: assignment makes pointer from integer without a cast mod_limitipconn.c: At top level: mod_limitipconn.c:224: warning: missing braces around initializer mod_limitipconn.c:224: warning: (near initialization for 'limitipconn_cmds[0].func') mod_limitipconn.c:224: warning: initialization from incompatible pointer type mod_limitipconn.c:226: warning: initialization from incompatible pointer type mod_limitipconn.c:228: warning: initialization from incompatible pointer type mod_limitipconn.c:234: error: expected declaration specifiers or '...' before 'pool' mod_limitipconn.c: In function 'limitipconn_init': mod_limitipconn.c:236: warning: passing argument 4 of 'ap_log_error' makes integer from pointer without a cast mod_limitipconn.c:236: warning: passing argument 5 of 'ap_log_error' from incompatible pointer type mod_limitipconn.c:236: error: too few arguments to function 'ap_log_error' mod_limitipconn.c: At top level: mod_limitipconn.c:239: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'limitipconn_module' apxs:Error: Command failed with rc=65536 . make: *** [mod_limitipconn.so] Error 1 ------------- apache は DSOをサポートしています。 (httpd -l | grep mod_so.c で確認) どうぞ宜しくお願いいたします。

  • makeのエラー【g++がみつからない】

    turbolinux10serverにmysqlをインストールしようとしています。 ですが、makeに失敗してしまいます。 エラーは以下のようなものを吐いています。 term.c: In function `term_set': term.c:941: warning: passing arg 3 of `term_alloc' makes pointer from integer without a cast term.c: In function `term_echotc': term.c:1445: warning: assignment makes pointer from integer without a cast ../depcomp: line 512: exec: g++: not found make[2]: *** [my_new.o] Error 127 make[1]: *** [all-recursive] Error 1 make: *** [all] Error 2 これを見ると、g++がないという旨のメッセージだと思います。 それならばg++をインストールすれば良いか、と思ったのですが、、、 どこにあるのか、また、どうインストールすればよいかが分かりません。 どなたか、ご教授願います。よろしくお願いします。

    • ベストアンサー
    • MySQL
  • 多次元配列の受渡しでの警告

    多次元配列を関数に受け渡す際に、 警告: passing argument 1 of ‘mat_add’ from incompatible pointer type 警告: passing argument 2 of ‘mat_add’ from incompatible pointer type のような警告が出てきてしまいます。 プログラムは、明解C言語(柴田望洋著)で紹介されているサンプルプログラムなのですが(下に載せておきます)、どうしてこのような警告がでるのか分からず困っています。 多次元配列の渡し方になにか問題があるのでしょうか? #include <stdio.h> void mat_add(const int ma[][3], const int mb[][3], int mc[][3]) { int i,j; for(i=0; i<2; i++) for(j=0; j<3; j++) mc[i][j] = ma[i][j] + mb[i][j]; } int main(void) { int i,j; int ma[2][3] = {{9,2,-3},{4,5,1}}; int mb[2][3] = {{9,2,-3},{4,5,1}}; int mc[2][3] = {0}; mat_add(ma, mb, mc); for(i=0; i<2; i++){ for(j=0; j<3; j++) printf("%3d",mc[i][j]); putchar('\n'); } return(0); }

  • printf()関数の括弧を二重にして、printf((~~~))とし

    printf()関数の括弧を二重にして、printf((~~~))として コンパイル/実行すると、実行時セグメンテーション違反が発生します。 コンパイル時には警告も発生しますが、このセグメンテーション違反が なぜ起こるのか理由がよくわかりません。ご回答いただけるとありがたいです。 以下、サンプルコードと実行例です。よろしくお願いいたします。 ---mytest.c---- 1 #include <stdio.h> 2 3 int main(void){ 4 5 //printf("test:%d", 1)ではもちろんコンパイル/実行に成功する。 6 printf(("test:%d", 1)); 7 return 0; 8 } 【コンパイル/実行結果/gccバージョン】 #gcc main.c main.c:6:警告:passing argument 1 of printf makes pointer from integer without a cast #./a.out セグメンテーション違反です # gcc --version gcc (GCC) 4.1.2 20070925 (Red Hat 4.1.2-27) ・ ・

専門家に質問してみよう