任务单 #38911

MinGW results in incorrect compilations of program

开放日期: 2019-01-30 18:29 最后更新: 2019-01-31 00:49

报告人:
属主:
(无)
类型:
状态:
关闭
组件:
里程碑:
(无)
优先:
5 - Medium
严重性:
5 - Medium
处理结果:
Invalid
文件:
1
Vote
Score: 0
No votes
0.0% (0/0)
0.0% (0/0)

Details

The attached program, when compiled with MinGW, creates an application that on execution gives different results than if the program was compiled by GCC on Linux(i.e. Ubuntu)

任务单历史 (3/4 Histories)

2019-01-30 18:29 Updated by: sai_vamsi_adapa
  • New Ticket "MinGW results in incorrect compilations of program" created
2019-01-30 23:10 Updated by: sai_vamsi_adapa
评论

The problem was with the code, not the compiler. In Ubuntu, variables are initialized to 0, whereas in windows MinGW does not do this. This led to the false conclusion that compiler was at fault.

2019-01-31 00:49 Updated by: keith
  • 处理结果 Update from to Invalid
  • 状态 Update from 开启 to 关闭
评论

Yep. Failure to initialize the iterator variable, in a for loop, is a user error ... not a compiler bug. Even if Ubuntu's compiler has (apparently) initialized it suitably, in this case, that's not a feature you should rely on ... ever. References to uninitialized variables always induce undefined behaviour, which is always a programming error.

I guess you resolved this by yourself, so I'm closing the ticket.

Attachment File List

  • red.c(1KB)
    • the file containing the code mentioned and the outputs achieved when compiled using different methods

编辑

Please login to add comment to this ticket » 登录名