简体   繁体   English

Windows/Visual Studio 在完美的 C 程序上出现问题

[英]Windows/Visual Studio going wonky on a perfectly fine C program

Okay, no ego, maybe something is funny in the program, but GCC and Clang are compiling it fine and running it just as intended on Ubuntu 20.04 and MacOS 10.14.好吧,不要自负,也许程序中有些东西很有趣,但是 GCC 和 Clang 正在编译它并按预期在 Z3D945423F8E9496C429A5D14.04 和 MacOS 上运行它。 Visual Studio 2013 on Win 7? Win 7 上的 Visual Studio 2013? Thats a different story.那是一个不同的故事。

    #include <stdio.h>
    #include <math.h>

    int main()
    {   double num1, num2, result; 
        printf("\nEnter numbers : ");
        scanf("%lf %lf", &num1, &num2);
        result = pow(num1,num2);
        printf("\n%s %lf\n","Result = ",result);
   }

Cool?凉爽的? On Mac/Linux When i try 128^128, I get the accurate answer 528294531135665246352339784916516606518847326036121522127960709026673902556724859474417255887657187894674394993257128678882347559502685537250538978462939576908386683999005084168731517676426441053024232908211188404148028292751561738838396898767036476489538580897737998336.000000 On Mac/Linux When i try 128^128, I get the accurate answer 528294531135665246352339784916516606518847326036121522127960709026673902556724859474417255887657187894674394993257128678882347559502685537250538978462939576908386683999005084168731517676426441053024232908211188404148028292751561738838396898767036476489538580897737998336.000000

When compiled without errors or warnings in VS2013, and run on the same machine (Win7Pro) i get:在 VS2013 中编译时没有错误或警告,并在同一台机器(Win7Pro)上运行,我得到:

52829453113566525 followed by many zeroes such that the answer has the same number of digits as the above answer. 52829453113566525后跟许多零,以使答案与上述答案具有相同的位数。

I can verify its the same code, i'm using the same.c file across these platforms, the only variables i see are the compiler and the OS.我可以验证其相同的代码,我在这些平台上使用相同的.c 文件,我看到的唯一变量是编译器和操作系统。 Is there anything a little developer like me can do to fix Microsoft's mess (as it appears to be)??像我这样的小开发人员能做些什么来解决微软的烂摊子(看起来是这样)?

Note: All Operating systems are 64-bit.注意:所有操作系统都是 64 位的。

Edit: This is a minimal reproducible example from a larger project, MathHack, which is available @ sites.google.com/view/mathhack The full source code is available on that website, although i doubt there's an issue with the rest of the code.编辑:这是来自更大项目 MathHack 的最小可重现示例,可在@ sites.google.com /view/mathhack 获得完整的源代码可在该网站上找到,尽管我怀疑代码的 rest 存在问题.

Edit 2: Screenshots -编辑 2:截图 -

Working on MacOSX 10.14 --在 MacOSX 10.14 上工作——

https://drive.google.com/file/d/1I0T75vJAUPnbK8y-oCkl_rHSqLTvCWzv/view?usp=sharing https://drive.google.com/file/d/1I0T75vJAUPnbK8y-oCkl_rHSqLTvCWzv/view?usp=sharing

Not Working on Win7 SP2 --不能在 Win7 SP2 上工作——

https://drive.google.com/file/d/148EuhwYlrWRom4fIPT_wfkxdSIYya3ep/view?usp=sharing https://drive.google.com/file/d/148EuhwYlrWRom4fIPT_wfkxdSIYya3ep/view?usp=sharing

Edit 3:编辑3:

Perhaps this is a bug in printf() implementation by Microsoft.也许这是 Microsoft 在 printf() 实现中的一个错误。 Shucks.嘘。 I'll be upgrading to the latest VS to see if that fixes this.我将升级到最新的 VS,看看是否能解决这个问题。

This is not the answer but comments do not display images:这不是答案,但评论不显示图像:

Visual Studio 2019. Compiled as C code (/TC option) Visual Studio 2019。编译为 C 代码(/TC 选项)

The result:结果: 在此处输入图像描述

IMO it is fine海事组织很好

SSE experiment:上证实验:

int main()
{
    int sse = _set_SSE2_enable(1);
    double num1, num2, result;
    printf("\nEnter numbers : ");
    scanf("%lf %lf", &num1, &num2);
    result = pow(num1, num2);
    printf("\n SSE = %d, %s %lf\n", sse,  "Result = ", result);
    sse = _set_SSE2_enable(0);
    result = pow(num1, num2);
    printf("\n SSE = %d, %s %lf\n", sse, "Result = ", result);

}

在此处输入图像描述

x64 result: x64 结果: 在此处输入图像描述

This appears to be a bug in VS 2013's compiler's printf() implementation.这似乎是 VS 2013 编译器的 printf() 实现中的一个错误。

As suggested by @P__J__ I installed VS 2019 Community and that has solved the problem.正如@P__J__ 所建议的那样,我安装了 VS 2019 社区并解决了问题。 Thanks, P__J__.谢谢,P__J__。

There seems to be no hope for such issues except to just suck it up and move to the latest VS.这些问题似乎没有希望,除非只是把它吸起来并转移到最新的 VS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Windows Visual Studio for C中对数组进行Malloc(0)操作可使程序运行正常 - Malloc(0)ing an array in Windows Visual Studio for C allows the program to run perfectly fine 从linux到Windows 7上的Visual Studio 2010的C编程问题 - c programming issues going from linux to visual studio 2010 on windows 7 C程序因段错误而崩溃,但在LLDB下工作正常 - C program crashes with Seg Fault but work perfectly fine under LLDB 当程序运行正常时Valgrind大喊(C) - Valgrind yelling when the program works perfectly fine (C) Visual Studio中的C程序 - C program in Visual Studio 在带有Visual Studio Community 2015的Windows上使用PostgreSQL构建C程序 - Building a C Program using PostgreSQL on Windows with Visual Studio Community 2015 如何在Visual Studio 2012 for Windows 8上编译和执行C程序? - How to compile and execute C program on Visual Studio 2012 for Windows 8? 在 Visual Studio 中检测到堆损坏,但程序在另一个 C 编译器中运行良好:为什么? - Heap Corruption Detected in Visual Studio, but program runs fine in another C compiler: why? 使用visual studio编译C程序 - Compile C program with visual studio 这个C程序在Windows中可以正常工作,但在Linux中不能正常工作 - This c program works fine in windows but not working in Linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM