Thread overview | ||||||
---|---|---|---|---|---|---|
|
May 07, 2004 a few (newbish?) questions about D... | ||||
---|---|---|---|---|
| ||||
Hi, I have a few simple questions about D. First off, why is it that if i run 'mydprogram one_arg', args.length equals 2? Something i'm missing? seems like just one argument was passed. Does the name as the program count as an argument? Second off, in C arrays are declared in the order of short bob[numarrays:2][num_vars_per_array:3] = { {1,2,3}, {1,2,3} }; why does D take such a different approach with short [num_vars_per_array:3][numarrays:2] = [ [1,2,3], [1,2,3] ]; Is there something really useful i'm missing here? It seems like it just makes it harder to convert C++ code to D, and as a c/c++ guy it is just confusing. |
May 07, 2004 Re: a few (newbish?) questions about D... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Claydoo | "Claydoo" <Claydoo_member@pathlink.com> wrote in message news:c7gp9d$1ch8$1@digitaldaemon.com... > Hi, I have a few simple questions about D. > > First off, why is it that if i run 'mydprogram one_arg', args.length equals 2? > Something i'm missing? seems like just one argument was passed. Does the name as > the program count as an argument? That's correct, args[0] is the program name used. > > Second off, in C arrays are declared in the order of > > short bob[numarrays:2][num_vars_per_array:3] = > { > {1,2,3}, > {1,2,3} > }; > > why does D take such a different approach with > > short [num_vars_per_array:3][numarrays:2] = > [ > [1,2,3], > [1,2,3] > ]; > > Is there something really useful i'm missing here? It seems like it just makes > it harder to convert C++ code to D, and as a c/c++ guy it is just confusing. D's way makes it easier to parse. Encounter [], it's an array; {}, it's a struct. -- Christopher E. Miller |
May 07, 2004 Re: a few (newbish?) questions about D... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix | Vathix wrote: >>short bob[numarrays:2][num_vars_per_array:3] = >>short [num_vars_per_array:3][numarrays:2] = (should be short [num_vars_per_array:3][numarrays:2] *bob* =, no?) > D's way makes it easier to parse. Encounter [], it's an array; {}, it's a > struct. I read it as wondering why the order is changed... I have no answer for that, however, but I assume there's likely a reason. -[Unknown] |
May 07, 2004 Re: a few (newbish?) questions about D... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix | On Fri, 7 May 2004 15:56:40 -0400, "Vathix" <vathixSpamFix@dprogramming.com> wrote: >"Claydoo" <Claydoo_member@pathlink.com> wrote in message news:c7gp9d$1ch8$1@digitaldaemon.com... >> Hi, I have a few simple questions about D. > >> >> Second off, in C arrays are declared in the order of >> >> short bob[numarrays:2][num_vars_per_array:3] = >> { >> {1,2,3}, >> {1,2,3} >> }; >> >> why does D take such a different approach with >> >> short [num_vars_per_array:3][numarrays:2] = >> [ >> [1,2,3], >> [1,2,3] >> ]; >> >> Is there something really useful i'm missing here? It seems like it just >makes >> it harder to convert C++ code to D, and as a c/c++ guy it is just >confusing. > consider the C typedef int IA[4] typedef IA myData[3] IA is int[4] myData is (int[4])[3] or int myData[3][4] <- more confusing if its more complex as in : int[][char[]][] is array of ( assoc(key=char[], value=int[]) ) something[] where something is val[key] with val=int[], key=char[] simple to mix arrays of arrays of hashes od arrays of hashes of ...... may seem odd if you come from a C background, but once you use it you'll never look back. Mike. |
Copyright © 1999-2021 by the D Language Foundation