具有double类型的可变数字参数的函数的奇怪输出

时间:2015-09-19 03:03:23

标签: c++ c

我尝试使用可变数量的整数参数,它按预期工作。但是,当我尝试使用" double"类型的可变数量的参数时,它给出了奇怪的输出:

$ g++ -fpermissive -std=c++11 te2d.cc
te2d.cc: In function ‘void maxof(double, long int, ...)’:
te2d.cc:19:16: warning: return-statement with a value, in function returning 'void' [-fpermissive]
$ ./a.out
dum=100.200000
debug 1 0.000000
debug 2 0.000000
debug 3 -5486124068793688683255936251187209270074392635932332070112001988456197381759672947165175699536362793613284725337872111744958183862744647903224103718245670299614498700710006264535590197791934024641512541262359795191593953928908168990292758500391456212260452596575509589842140073806143686060649302051520512.000000
debug 4 0.000000

这是简短的代码:

#include <stdio.h>
#include <stdarg.h>
typedef unsigned char uchar;
typedef unsigned short uint16;
using namespace std;
typedef unsigned char uchar;
void maxof(double dum, long n_args, ...){
        printf("dum=%f\n", dum);
        register int i;
        int max = 0;
        va_list ap;

        va_start(ap, n_args);
        for(i = 1; i <= n_args; i++) {
            printf("debug %d %f\n", i, va_arg(ap, double));
        }

        va_end(ap);
        return max;
}

int main(int argc, char *argv[]) {
    maxof(100.2, 4, 10,14,13,11);
    return 0;
}

有什么想法吗?感谢。

0 个答案:

没有答案