473,668 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Two dimensional array initialization

Hi,

I can make a simple initialization work like this:

Object[,] ONE_ROW = {{"Vodafone", "55501601001970 16"}};

But, now I want to create another array that consists of multiple copies of ONE_ROW like this (will not compile):

Object[,] TWO_ROWS = {ONE_ROW, ONE_ROW}; // Works in Java ;-)

This yields "Incorrectl y structured array initializer"!!

This, however, is a correct implementation using hard-coded data:

Object[,] TWO_ROWS = {{"Vodafone", "55501601001970 16"}, {"Vodafone", "55501601001970 16"}};

Any ideas?

Regards,
Dadi.
Nov 15 '05 #1
9 8572
Dadi <da**@hugur.i s> wrote:
I can make a simple initialization work like this:

Object[,] ONE_ROW = {{"Vodafone", "55501601001970 16"}};

But, now I want to create another array that consists of multiple copies
of ONE_ROW like this (will not compile):


It sounds like you want jagged arrays then, rather than rectangular
arrays. If you do:

Object[][,] TWO_ROWS = {ONE_ROW, ONE_ROW}; I believe it'll work.

(Haven't tried it though...)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Actually Jon I think he wants

Object[][] TWO_ROWS =

a jagged array of ONE_ROW arrays. Your code would be a jagged array of 2D
rectangular arrays which I don't think was the intent, wouldn't it?

I've been wrong about arrays before so maybe I am again.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Dadi <da**@hugur.i s> wrote:
I can make a simple initialization work like this:

Object[,] ONE_ROW = {{"Vodafone", "55501601001970 16"}};

But, now I want to create another array that consists of multiple copies
of ONE_ROW like this (will not compile):


It sounds like you want jagged arrays then, rather than rectangular
arrays. If you do:

Object[][,] TWO_ROWS = {ONE_ROW, ONE_ROW}; I believe it'll work.

(Haven't tried it though...)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #3
Daniel Billingsley <db**********@N O.durcon.SPAAMM .com> wrote:
Actually Jon I think he wants

Object[][] TWO_ROWS =

a jagged array of ONE_ROW arrays. Your code would be a jagged array of 2D
rectangular arrays which I don't think was the intent, wouldn't it?


I don't know - the intent wasn't very clear! However, my code would
give a single array of 2D rectangular arrays.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
That's what I said, isn't it? :)

I meant your overall array [][,] would be jagged, as opposed to simply 3D
[,,].

Yes, no, maybe so? (Trying to see if I'm starting to grasp this terminology
as well as I think I am.)

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
... Your code would be a jagged array of 2D
rectangular arrays which I don't think was the intent, wouldn't it?


I don't know - the intent wasn't very clear! However, my code would
give a single array of 2D rectangular arrays.

Nov 15 '05 #5
Daniel Billingsley <db**********@N O.durcon.SPAAMM .com> wrote:
That's what I said, isn't it? :)
Not quite - it's definitely *not* a jagged array *of* 2D rectangular
arrays, in the same way that int[] isn't a jagged array of ints, it's
just an array of ints, if you see what I mean.
I meant your overall array [][,] would be jagged, as opposed to simply 3D
[,,].


I'm not sure whether I'd say the overall array is jagged or not - it's
certainly not rectangular, but it's not jagged in the normal sense
either.

Fortunately this is unlikely to actually be an issue very often :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
Hmm... I thought jagged simply meant an array of arrays... what did you mean
by the "normal sense" of jagged usage?

an array of ints is 1 dimensional, and not relevant to this discussion in my
mind.

an array of arrays, or an array of arrays of arrays, or an array of 2D
arrays, are all "jagged" I would think by definition, no?

[,] defines 2D array, definitely not jagged
[][] defines array of arrays, definitely jagged

[][,] defines an array of 2D arrays, jagged, right?
[][][] defines an array of arrays of arrays, jagged, right?
[,,] defines a 3D array, not jagged, right?

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Daniel Billingsley <db**********@N O.durcon.SPAAMM .com> wrote:
That's what I said, isn't it? :)


Not quite - it's definitely *not* a jagged array *of* 2D rectangular
arrays, in the same way that int[] isn't a jagged array of ints, it's
just an array of ints, if you see what I mean.
I meant your overall array [][,] would be jagged, as opposed to simply 3D [,,].


I'm not sure whether I'd say the overall array is jagged or not - it's
certainly not rectangular, but it's not jagged in the normal sense
either.

Fortunately this is unlikely to actually be an issue very often :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #7
Daniel Billingsley <db**********@N O.durcon.SPAAMM .com> wrote:
Hmm... I thought jagged simply meant an array of arrays... what did you mean
by the "normal sense" of jagged usage?
I'd say that a jagged array of "X"s is an array of arrays of "X"s.
an array of ints is 1 dimensional, and not relevant to this discussion in my
mind.
Ah, but it is in mine. Here's a jagged array of ints:

int[][] x;

That means a jagged array *of* arrays is similarly:

Something[][][] x;

That's a jagged array of (Something[]).

Just

Something[][] x;

is a jagged array of (Something) instead.

In this case we have:

Something[][,];

which is a one-dimensional array of (Something[,]), rather than a
jagged array of Something[,]. It may or may not (see below) count as a
jagged array of Something. Semi-jagged perhaps?
an array of arrays, or an array of arrays of arrays, or an array of 2D
arrays, are all "jagged" I would think by definition, no?


Not sure. Possibly, possibly not. My main point was that it wasn't a
jagged array of 2D arrays, but now we're getting into deeper water :)

I keep flip-flopping on whether or not I'd consider it jagged in
general. I think I probably would, on balance, contrary to my previous
post.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #8
I'm sure where you landed when you flip-flopped, so I don't know if we're
still disagreeing. :)

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Daniel Billingsley <db**********@N O.durcon.SPAAMM .com> wrote:
Hmm... I thought jagged simply meant an array of arrays... what did you mean by the "normal sense" of jagged usage?
I'd say that a jagged array of "X"s is an array of arrays of "X"s.


Yes I agree. MS defines a jagged array as "an array whose elements are
arrays." But there is no specification of what that second "of arrays"
looks like - 1D, 2D, 3D doesn't change the definition.

Something[][,];

which is a one-dimensional array of (Something[,]), rather than a
jagged array of Something[,]. It may or may not (see below) count as a
jagged array of Something. Semi-jagged perhaps?
Is Something[,] not an array? Then that makes Something[][,] an
array of arrays, and therefore jagged by definition, just as MS explains a
bit further down on that same doc page:

"It is possible to mix jagged and multidimensiona l arrays. The following is
a declaration and initialization of a single-dimensional jagged array that
contains two-dimensional array elements of different sizes:

int [] [,] myJaggedArray = new int [] [3,] { new int [,] " blah blah blah

Not sure. Possibly, possibly not. My main point was that it wasn't a
jagged array of 2D arrays, but now we're getting into deeper water :)


Sure looks to me like MS just said [][,] is a jagged array of 2D arrays.

I'm sorry, I'm not trying to be a smart alec proving you wrong per se.. it's
just that I find myself completely confused and wrong enough that when I
think I've got something nailed for once I've got to cling to it
desperately. LOL.
Nov 15 '05 #9
I meant I'm *NOT* sure, of course. I've been typing like a retard all day.
Need coffee.

"Daniel Billingsley" <db**********@N O.durcon.SPAAMM .com> wrote in message
news:us******** ******@TK2MSFTN GP11.phx.gbl...
I'm sure where you landed when you flip-flopped, so I don't know if we're
still disagreeing. :)

Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7660
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray = (data_type**)malloc(widht*height*sizeof(data_type)+ height* sizeof(data_type*)); //allocate individual addresses for row pointers. Now that I am moving to C++,am looking for something by which I can
4
26527
by: Grumble | last post by:
Hello, Is it not legal in C90 to initialize a multi-dimensional array with a one-dimensional initializer as done below? int a = { 1, 2, 3, 4, 5, 6, 7, 8 }; My compiler complains: example.c:1: warning: missing braces around initializer example.c:1: warning: (near initialization for `a')
4
2245
by: Richard Hayden | last post by:
Hi, Why does gcc (3.3.2) give me a 'initialization from incompatible pointer type' warning when compiling: int main(int argc, char** argv) { int testa; int** testp = testa; }
7
5820
by: ashu | last post by:
look at code #include<stdio.h> int *mult(void); int main(void) { int *ptr,i; ptr=mult; for(i=0;i<6;i++) { printf("%d",*(ptr++));
4
2303
by: TG | last post by:
Hi there ! I'm just starting to use Numeric here, and I'm wondering : how can I efficiently initialize every values of a N-dimensional array, given I don't know the number of dimensions ? I'm looking for something like a map function, or a way to conveniently iterate through the whole N-array, but I didn't find anything ... yet. If anyone has a clue, I'm listening.
8
2668
by: kd | last post by:
Newbie question here. It's been a while since I've done C programming, and I hit a wall last night. Let's say I have a three dimensional array, like so: int p = {{{0,0,0}, {1,1,1}, {0,1,0}},
5
1624
by: David T. Ashley | last post by:
Hi, Aside from the obvious recursive syntax for initialization, $x = array( ... array( ...)), what is the best way to deal with multi-dimensional arrays in PHP? It seems there is no syntax like $x???
4
559
by: Gernot Frisch | last post by:
Hi, I need a class, that has a 4 dimensional array (can be 3 dimensional, too) with such an operator: T operator()(int x1, int x2=0, int x3=0, int x4=0); that can be used as:
152
9820
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { { 3.14 }, { 42.6 } }; f((double *)array, sizeof array / sizeof **array); return 0;
0
8889
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8790
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8572
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7391
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2782
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.