2 param Problems

Fabian Claßen admin at fabs-world.de
Sun Nov 30 10:51:33 PST 2008


Hi
I've learned the D language for a few days.
I've worked in other languages before.
But now I have following problems:

First:

import std.stdio;

double add(double param[] ...) {
	double result = 0;
	foreach(double d; param) {
		result += d;
	}
	return result;
}

int main() {
	double zahl;
	zahl = add(2, 5.6, 7.8);
	writefln("%d", zahl);
	return 0;
}

___________________________________________________________

Second:

import std.stdio;
import std.format;

int main() {
	double zahl = add(1, 5.6, 41, "Hello");
	writefln("%d", zahl);
	return 0;
}

double add(...) {
	double result = 0;
	for(int i=0; i < _arguments.length; i++) {
		if(_arguments[i] == typeid(double)) {
			double var = *cast(double*)_argptr;
			result += var;
			_argptr += double.sizeof;
		} else if(_arguments[i] == typeid(float)) {
			float var = *cast(float*)_argptr;
			result += var;
			_argptr += double.sizeof;
		} else if(_arguments[i] == typeid(int)) {
			int var = *cast(int*)_argptr;
			result += var;
			_argptr += int.sizeof;
		} else if(_arguments[i] == typeid(bool)) {
			_argptr += bool.sizeof;
		} else if(_arguments[i] == typeid(char[])) {
			char[] var = *cast(char[]*)_argptr;
			_argptr += var.sizeof;
		}
	}
	return result;
}

When I try to run this codes there is printed following message in the cmd:

Error: std.format floating

Please help me. I have no idea.

Greetings
Fabian Claßen



More information about the Digitalmars-d mailing list