www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - a few (newbish?) questions about D...

reply Claydoo <Claydoo_member pathlink.com> writes:
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
parent reply "Vathix" <vathixSpamFix dprogramming.com> writes:
"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
next sibling parent "Unknown W. Brackets" <unknown at.simplemachines.dot.org> writes:
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
prev sibling parent Mike Wynn <one_mad_alien hotmail.com> writes:
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.
May 07 2004