Array of array of recordsCreate ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?Deleting an element from an array in PHPHow to insert an item into an array at a specific index (JavaScript)?How do I empty an array in JavaScript?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
How to deal with my team leader who keeps calling me about project updates even though I am on leave for personal reasons?
Pandas aggregate with dynamic column names
Why NASA publish all the results/data it gets?
Can multiple wall timers turn lights on or off when required?
Can someone explain to me the parameters of a lognormal distribution?
How to make interviewee comfortable interviewing in lounge chairs
Writing a letter of recommendation for a mediocre student
Algorithm that spans orthogonal vectors: Python
What is the need of methods like GET and POST in the HTTP protocol?
How do I improve in sight reading?
I reverse the source code, you negate the output!
Spectrum of a Subspace of Matrices
How could artificial intelligence harm us?
Apple Developer Program Refund Help
What are the end bytes of *.docx file format
Where Does VDD+0.3V Input Limit Come From on IC chips?
Leaving a job that I just took based on false promise of a raise. What do I tell future interviewers?
How do rulers get rich from war?
C# Fastest way to do Array Table Lookup with Integer Index
How to influence manager to not schedule team meetings during lunch?
I feel like most of my characters are the same, what can I do?
Nanomachines exist that enable Axolotl-levels of regeneration - So how can crippling injuries exist as well?
What was the deeper meaning of Hermione wanting the cloak?
When does removing Goblin Warchief affect its cost reduction ability?
Array of array of records
Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?Deleting an element from an array in PHPHow to insert an item into an array at a specific index (JavaScript)?How do I empty an array in JavaScript?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need to create a constant array of a constant array of records where I can reference each element of the outer array by a number.
I've tried:
A : constant array (0 .. 3) of B := (B1, B2, B3, B4)
where B is an array of records and B1,B2,B3,B4 are constant arrays of type B.
But when I do this I get the error:
"Unconstrained element type in array declaration"
type C is record
a : Integer := 0;
b : Integer := 0;
c : Integer := 0;
d : Integer := 0;
end record;
type B is array (Natural range <>) of C;
B1 : constant B := (0, 0, 0, 0);
B2 : constant B := (2, 0, 2, 0);
B3 : constant B := (0, 1, 0, 1);
B4 : constant B := (2, 1, 2, 1);
A : constant array (0 .. 3) of B := (B1, B2, B3, B4);
I was hoping to use A to be able to reference B1,B2,B3,B4 numerically like so:
A (1) returns B1
A (2) returns B2
and so on...
(I apologize if the terms I use are wrong. I'm kinda new to Ada and have been learning by trial and error...)
arrays record ada
add a comment
|
I need to create a constant array of a constant array of records where I can reference each element of the outer array by a number.
I've tried:
A : constant array (0 .. 3) of B := (B1, B2, B3, B4)
where B is an array of records and B1,B2,B3,B4 are constant arrays of type B.
But when I do this I get the error:
"Unconstrained element type in array declaration"
type C is record
a : Integer := 0;
b : Integer := 0;
c : Integer := 0;
d : Integer := 0;
end record;
type B is array (Natural range <>) of C;
B1 : constant B := (0, 0, 0, 0);
B2 : constant B := (2, 0, 2, 0);
B3 : constant B := (0, 1, 0, 1);
B4 : constant B := (2, 1, 2, 1);
A : constant array (0 .. 3) of B := (B1, B2, B3, B4);
I was hoping to use A to be able to reference B1,B2,B3,B4 numerically like so:
A (1) returns B1
A (2) returns B2
and so on...
(I apologize if the terms I use are wrong. I'm kinda new to Ada and have been learning by trial and error...)
arrays record ada
add a comment
|
I need to create a constant array of a constant array of records where I can reference each element of the outer array by a number.
I've tried:
A : constant array (0 .. 3) of B := (B1, B2, B3, B4)
where B is an array of records and B1,B2,B3,B4 are constant arrays of type B.
But when I do this I get the error:
"Unconstrained element type in array declaration"
type C is record
a : Integer := 0;
b : Integer := 0;
c : Integer := 0;
d : Integer := 0;
end record;
type B is array (Natural range <>) of C;
B1 : constant B := (0, 0, 0, 0);
B2 : constant B := (2, 0, 2, 0);
B3 : constant B := (0, 1, 0, 1);
B4 : constant B := (2, 1, 2, 1);
A : constant array (0 .. 3) of B := (B1, B2, B3, B4);
I was hoping to use A to be able to reference B1,B2,B3,B4 numerically like so:
A (1) returns B1
A (2) returns B2
and so on...
(I apologize if the terms I use are wrong. I'm kinda new to Ada and have been learning by trial and error...)
arrays record ada
I need to create a constant array of a constant array of records where I can reference each element of the outer array by a number.
I've tried:
A : constant array (0 .. 3) of B := (B1, B2, B3, B4)
where B is an array of records and B1,B2,B3,B4 are constant arrays of type B.
But when I do this I get the error:
"Unconstrained element type in array declaration"
type C is record
a : Integer := 0;
b : Integer := 0;
c : Integer := 0;
d : Integer := 0;
end record;
type B is array (Natural range <>) of C;
B1 : constant B := (0, 0, 0, 0);
B2 : constant B := (2, 0, 2, 0);
B3 : constant B := (0, 1, 0, 1);
B4 : constant B := (2, 1, 2, 1);
A : constant array (0 .. 3) of B := (B1, B2, B3, B4);
I was hoping to use A to be able to reference B1,B2,B3,B4 numerically like so:
A (1) returns B1
A (2) returns B2
and so on...
(I apologize if the terms I use are wrong. I'm kinda new to Ada and have been learning by trial and error...)
arrays record ada
arrays record ada
edited Mar 28 at 17:16
user3521388
asked Mar 28 at 15:04
user3521388user3521388
131 silver badge6 bronze badges
131 silver badge6 bronze badges
add a comment
|
add a comment
|
2 Answers
2
active
oldest
votes
Your problem is that B
is an unconstrained array:
type B is array (Natural range <>) of C;
This is fine for B1 : constant B := (0, 0, 0, 0);
, as the constant definition creates a new anonymous type, with the range taken from the Right-Hand-Side.
It is, however, not fine for A
. The compiler needs to know the size of the array elements, but cannot when the element (B
in this case) is unconstrained. In addition, the constraints ('First
, 'Last
, etc) must be the same for all of the elements.
You can change your definition of B
to be constrained:
type B is array (Natural range 1..4) of C;
This will force all your B1
, B2
, etc to always have four elements, which is what you already have in your example.
Also, if you want A(1)
to return B1
, you should change the range of A
to start at 1:
A : constant array (1 .. 4) of B := (B1, B2, B3, B4);
Thank you for your reply... I used constant size for B1,B2,B3,B4 but they are most likely not the same size... What I really need is a way of referencing B1,B2,B3, etc numerically and I thought an array would be a solution... I will try with variant records and see if that works...
– user3521388
Mar 28 at 17:19
not the same size... indexed numerically... You should take a look atAda.Containers.Indefinite_Vectors
– egilhh
Mar 28 at 17:21
add a comment
|
What is obvious to you is not obvious to the compiler, that is all your B's have four elements.
For accessing element A(3)(2) it (or the Ada language) wants to be able to make very simple arithmetic (2 + 3 * 4) * (size of an integer). An array of B (which is unconstrained) would make this computation too complicated. The produced machine code would need to add the sizes of A(0), A(1), A(2) just to get to A(3)(0).
Of course you can imagine the time it would take for much larger array lengths, just for accessing element A(1234)(5678) for instance.
This is why the designers of Ada wisely required to have always arrays of constrained types. For your problem, you can solve it by defining subtype BL4 is B (0 .. 3);
and use BL4 instead of B for B1, B2, B3, B4 and A.
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400876%2farray-of-array-of-records%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your problem is that B
is an unconstrained array:
type B is array (Natural range <>) of C;
This is fine for B1 : constant B := (0, 0, 0, 0);
, as the constant definition creates a new anonymous type, with the range taken from the Right-Hand-Side.
It is, however, not fine for A
. The compiler needs to know the size of the array elements, but cannot when the element (B
in this case) is unconstrained. In addition, the constraints ('First
, 'Last
, etc) must be the same for all of the elements.
You can change your definition of B
to be constrained:
type B is array (Natural range 1..4) of C;
This will force all your B1
, B2
, etc to always have four elements, which is what you already have in your example.
Also, if you want A(1)
to return B1
, you should change the range of A
to start at 1:
A : constant array (1 .. 4) of B := (B1, B2, B3, B4);
Thank you for your reply... I used constant size for B1,B2,B3,B4 but they are most likely not the same size... What I really need is a way of referencing B1,B2,B3, etc numerically and I thought an array would be a solution... I will try with variant records and see if that works...
– user3521388
Mar 28 at 17:19
not the same size... indexed numerically... You should take a look atAda.Containers.Indefinite_Vectors
– egilhh
Mar 28 at 17:21
add a comment
|
Your problem is that B
is an unconstrained array:
type B is array (Natural range <>) of C;
This is fine for B1 : constant B := (0, 0, 0, 0);
, as the constant definition creates a new anonymous type, with the range taken from the Right-Hand-Side.
It is, however, not fine for A
. The compiler needs to know the size of the array elements, but cannot when the element (B
in this case) is unconstrained. In addition, the constraints ('First
, 'Last
, etc) must be the same for all of the elements.
You can change your definition of B
to be constrained:
type B is array (Natural range 1..4) of C;
This will force all your B1
, B2
, etc to always have four elements, which is what you already have in your example.
Also, if you want A(1)
to return B1
, you should change the range of A
to start at 1:
A : constant array (1 .. 4) of B := (B1, B2, B3, B4);
Thank you for your reply... I used constant size for B1,B2,B3,B4 but they are most likely not the same size... What I really need is a way of referencing B1,B2,B3, etc numerically and I thought an array would be a solution... I will try with variant records and see if that works...
– user3521388
Mar 28 at 17:19
not the same size... indexed numerically... You should take a look atAda.Containers.Indefinite_Vectors
– egilhh
Mar 28 at 17:21
add a comment
|
Your problem is that B
is an unconstrained array:
type B is array (Natural range <>) of C;
This is fine for B1 : constant B := (0, 0, 0, 0);
, as the constant definition creates a new anonymous type, with the range taken from the Right-Hand-Side.
It is, however, not fine for A
. The compiler needs to know the size of the array elements, but cannot when the element (B
in this case) is unconstrained. In addition, the constraints ('First
, 'Last
, etc) must be the same for all of the elements.
You can change your definition of B
to be constrained:
type B is array (Natural range 1..4) of C;
This will force all your B1
, B2
, etc to always have four elements, which is what you already have in your example.
Also, if you want A(1)
to return B1
, you should change the range of A
to start at 1:
A : constant array (1 .. 4) of B := (B1, B2, B3, B4);
Your problem is that B
is an unconstrained array:
type B is array (Natural range <>) of C;
This is fine for B1 : constant B := (0, 0, 0, 0);
, as the constant definition creates a new anonymous type, with the range taken from the Right-Hand-Side.
It is, however, not fine for A
. The compiler needs to know the size of the array elements, but cannot when the element (B
in this case) is unconstrained. In addition, the constraints ('First
, 'Last
, etc) must be the same for all of the elements.
You can change your definition of B
to be constrained:
type B is array (Natural range 1..4) of C;
This will force all your B1
, B2
, etc to always have four elements, which is what you already have in your example.
Also, if you want A(1)
to return B1
, you should change the range of A
to start at 1:
A : constant array (1 .. 4) of B := (B1, B2, B3, B4);
edited Mar 28 at 15:22
answered Mar 28 at 15:16
egilhhegilhh
4,3571 gold badge11 silver badges19 bronze badges
4,3571 gold badge11 silver badges19 bronze badges
Thank you for your reply... I used constant size for B1,B2,B3,B4 but they are most likely not the same size... What I really need is a way of referencing B1,B2,B3, etc numerically and I thought an array would be a solution... I will try with variant records and see if that works...
– user3521388
Mar 28 at 17:19
not the same size... indexed numerically... You should take a look atAda.Containers.Indefinite_Vectors
– egilhh
Mar 28 at 17:21
add a comment
|
Thank you for your reply... I used constant size for B1,B2,B3,B4 but they are most likely not the same size... What I really need is a way of referencing B1,B2,B3, etc numerically and I thought an array would be a solution... I will try with variant records and see if that works...
– user3521388
Mar 28 at 17:19
not the same size... indexed numerically... You should take a look atAda.Containers.Indefinite_Vectors
– egilhh
Mar 28 at 17:21
Thank you for your reply... I used constant size for B1,B2,B3,B4 but they are most likely not the same size... What I really need is a way of referencing B1,B2,B3, etc numerically and I thought an array would be a solution... I will try with variant records and see if that works...
– user3521388
Mar 28 at 17:19
Thank you for your reply... I used constant size for B1,B2,B3,B4 but they are most likely not the same size... What I really need is a way of referencing B1,B2,B3, etc numerically and I thought an array would be a solution... I will try with variant records and see if that works...
– user3521388
Mar 28 at 17:19
not the same size... indexed numerically... You should take a look at
Ada.Containers.Indefinite_Vectors
– egilhh
Mar 28 at 17:21
not the same size... indexed numerically... You should take a look at
Ada.Containers.Indefinite_Vectors
– egilhh
Mar 28 at 17:21
add a comment
|
What is obvious to you is not obvious to the compiler, that is all your B's have four elements.
For accessing element A(3)(2) it (or the Ada language) wants to be able to make very simple arithmetic (2 + 3 * 4) * (size of an integer). An array of B (which is unconstrained) would make this computation too complicated. The produced machine code would need to add the sizes of A(0), A(1), A(2) just to get to A(3)(0).
Of course you can imagine the time it would take for much larger array lengths, just for accessing element A(1234)(5678) for instance.
This is why the designers of Ada wisely required to have always arrays of constrained types. For your problem, you can solve it by defining subtype BL4 is B (0 .. 3);
and use BL4 instead of B for B1, B2, B3, B4 and A.
add a comment
|
What is obvious to you is not obvious to the compiler, that is all your B's have four elements.
For accessing element A(3)(2) it (or the Ada language) wants to be able to make very simple arithmetic (2 + 3 * 4) * (size of an integer). An array of B (which is unconstrained) would make this computation too complicated. The produced machine code would need to add the sizes of A(0), A(1), A(2) just to get to A(3)(0).
Of course you can imagine the time it would take for much larger array lengths, just for accessing element A(1234)(5678) for instance.
This is why the designers of Ada wisely required to have always arrays of constrained types. For your problem, you can solve it by defining subtype BL4 is B (0 .. 3);
and use BL4 instead of B for B1, B2, B3, B4 and A.
add a comment
|
What is obvious to you is not obvious to the compiler, that is all your B's have four elements.
For accessing element A(3)(2) it (or the Ada language) wants to be able to make very simple arithmetic (2 + 3 * 4) * (size of an integer). An array of B (which is unconstrained) would make this computation too complicated. The produced machine code would need to add the sizes of A(0), A(1), A(2) just to get to A(3)(0).
Of course you can imagine the time it would take for much larger array lengths, just for accessing element A(1234)(5678) for instance.
This is why the designers of Ada wisely required to have always arrays of constrained types. For your problem, you can solve it by defining subtype BL4 is B (0 .. 3);
and use BL4 instead of B for B1, B2, B3, B4 and A.
What is obvious to you is not obvious to the compiler, that is all your B's have four elements.
For accessing element A(3)(2) it (or the Ada language) wants to be able to make very simple arithmetic (2 + 3 * 4) * (size of an integer). An array of B (which is unconstrained) would make this computation too complicated. The produced machine code would need to add the sizes of A(0), A(1), A(2) just to get to A(3)(0).
Of course you can imagine the time it would take for much larger array lengths, just for accessing element A(1234)(5678) for instance.
This is why the designers of Ada wisely required to have always arrays of constrained types. For your problem, you can solve it by defining subtype BL4 is B (0 .. 3);
and use BL4 instead of B for B1, B2, B3, B4 and A.
edited Mar 28 at 16:01
answered Mar 28 at 15:32
ZerteZerte
4873 silver badges6 bronze badges
4873 silver badges6 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400876%2farray-of-array-of-records%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown