GCC - shouldn't a warning be issued when assigning an int to a char?

前端 未结 6 2008
你的背包
你的背包 2020-12-19 05:47

I\'ve recently set up a MinGW + MSYS environment on my laptop to check how things are with Netbeans C/C++ support. Everything seems to work fine, however, during my testing

6条回答
  •  攒了一身酷
    2020-12-19 06:08

    I didnt get a warning/error with -Wconversion either. However, if you give a pass with something like splint you get three warnings:

    file.c: (in function main)
    file.c:9:5: Assignment of int to char: c = i_max
      To make char and int types equivalent, use +charint.
    file.c:10:52: Format argument 2 to printf (%d) expects int gets char: c_max
       file.c:10:32: Corresponding format code
    file.c:10:59: Format argument 3 to printf (%d) expects int gets char: c
       file.c:10:39: Corresponding format code
    
    Finished checking --- 3 code warnings
    

    If you are serious about catching all errors you should use more than one tool.

提交回复
热议问题