相关疑难解决方法(0)

MinGW不会发出警告

我已经在Windows 7 32位机器上成功安装了MinGW,并尝试使用命令行或MinGW控制台编译一个简单的程序.

代码在printf语句中有故意错误:

#include <stdio.h>
#include <stdlib.h>
int main( void )
{
    printf("%d\n" , 3.14 ) ;
return 0 ;
}
Run Code Online (Sandbox Code Playgroud)

该命令gcc -Wall hello.c给出了正确的警告:hello.c:7:2:警告:格式'%d'需要类型'int'的参数...

但该命令gcc -std=c99 -Wall hello.c没有给出任何警告.

两者都创建一个可执行文件a.exe(运行并给出相同的结果).

(有趣的是,命令gcc -std=gnu99 -Wall hello.c会发出警告.)

我不知道这是一个错误,还是安装出错了,但两者似乎都不太可能,因为编译器工作并成功编译了一个更大的项目(但当使用-std = c99时,同样的警告当然会被忽略).

我一定错过了一些信息.

(ps:如果有人安装了新的MinGW,请测试一下.)

gcc版本4.8.1(GCC)

更新1:

_GNU_SOURCE在包含之前定义stdio.h即使使用也会删除警告 gcc -Wall hello.c.

更新2(可能不太相关):

编译

 printf("%lf\n" , 3.14 ) ;
Run Code Online (Sandbox Code Playgroud)

-std=c99 标志输出:0.000000

-std=gnu99 输出:3.140000

并编译:

 printf("%f\n" , 3.14 ) ;
Run Code Online (Sandbox Code Playgroud)

-std=gnu99-std=c99输出:3.140000

更新3: …

c windows gcc mingw

19
推荐指数
1
解决办法
667
查看次数

奇怪的"unsigned long long int"行为

可能重复:
你如何printf unsigned long long int?

#include <cstdio>

int main ()
{
    unsigned long long int n;
    scanf("%llu",&n);
    printf("n: %llu\n",n);
    n /= 3;
    printf("n/3: %llu\n",n);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

无论我输入什么,我都会得到非常奇怪的输出,例如:

n: 1
n/3: 2863311531
Run Code Online (Sandbox Code Playgroud)

要么

n: 2
n/3: 2863311531
Run Code Online (Sandbox Code Playgroud)

要么

n: 1000
n/3: 2863311864
Run Code Online (Sandbox Code Playgroud)

什么原因?我该怎么做才能正确?

(g ++ 3.4.2,Win XP)

c c++

7
推荐指数
1
解决办法
2万
查看次数

我使用长双人的方式有什么问题吗?

我最近对学习c ++编程感兴趣,因为我想更深入地了解计算机的工作方式和处理指令.我以为我会尝试数据类型,但我真的不明白我的输出发生了什么......

#include <iostream>
#include <iomanip>

using namespace std;

int main() {

    float fValue = 123.456789;
    cout << setprecision(20) << fixed << fValue << endl;
    cout << "Size of float: " << sizeof(float) << endl;

    double dValue = 123.456789;
    cout << setprecision(20) << fixed << dValue << endl;
    cout << "Size of double: " << sizeof(double) << endl;

    long double lValue = 123.456789;
    cout << setprecision(20) << fixed << lValue << endl;
    cout << "Size of long double: " << …
Run Code Online (Sandbox Code Playgroud)

c++

5
推荐指数
1
解决办法
378
查看次数

无法在C中正确打印长双

我正在尝试打印一个简单的长双,但它不起作用

我尝试了什么:

long double ld=5.32;

printf("ld with le = %Le \n",ld);
printf("ld with lf = %Lf \n",ld);
printf("ld with lg = %Lg \n",ld);
Run Code Online (Sandbox Code Playgroud)

输出:

ld with le = -3.209071e-105 
ld with lf = -0.000000 
ld with lg = -3.20907e-105 
Run Code Online (Sandbox Code Playgroud)

有了新的价值:

ld=6.72;
Run Code Online (Sandbox Code Playgroud)

输出:

ld with le = -1.972024e+111 
ld with lf = -1972024235903379200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000 
ld with lg = -1.97202e+111 
Run Code Online (Sandbox Code Playgroud)

c long-double

4
推荐指数
1
解决办法
5628
查看次数

C - long double和printf问题

我是新的C程序员,我正在研究一个学校项目,我必须估算值或pi.我的教授表示我们必须使用声明所有整数项long double.控制台显示我询问用户在给定函数时接近pi的项数.我输入1作为术语数,但代码返回-0.00000000而不是4.00000000.

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

long double approx1(int terms)
{
    long double pi = 0;
    long double num = 4;
    long double denom = 1;
    int i;

    for(i=1; i <= terms; i++)
    {
        if(i%2 != 0)
        {
            pi=pi+(num/denom);
        }
        else
        {
            pi=pi-(num/denom);
        }
        denom = denom + 2;
    }
     printf("%.8Lf\n", pi);
}

int main()
{
    int terms;
    long double pie;

    printf("input number of terms, input 0 to cancel\n");
    scanf("%d", &terms);

    while(terms != 0)
    {
        if(terms > 0) …
Run Code Online (Sandbox Code Playgroud)

c printf long-double

2
推荐指数
1
解决办法
286
查看次数

标签 统计

c ×4

c++ ×2

long-double ×2

gcc ×1

mingw ×1

printf ×1

windows ×1