Returning Arrays from Functions

Samwise via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 18 14:51:17 PST 2017


On Wednesday, 18 January 2017 at 22:37:25 UTC, Adam D. Ruppe 
wrote:
> What code do you have now?

This is the basic function. It takes all those boolean arguments 
and does things depending on them, and then takes any extra args 
that getopt didn't parse and reads them into numbs. That code 
works fine, because I write it out after that's done but before I 
pass it back to main().

ulong[] getInp (bool help, bool file, bool inp, string[] args) {
	//...
	writeln(numbs);
	return numbs;
}

Here is what I've got in main (Minus some more stuff). Right now 
it's just printing out what it gets, but it will use other 
functions to apply operations to numbs later.

int main(string[] args) {
         ulong[] numbs;
         //...
	numbs[] = getInp(help, file, inp, args);

	writeln(numbs);
	return 0;
}

That prints out an empty array. If I initialize one element, 
(numbs[0] ~= 0;) then it prints out numbs.length. Really kinda 
weird... Thanks,
~Sam


More information about the Digitalmars-d-learn mailing list