I've put together a demo to reproduce a strange behavior of a cursor.
https://github.com/Blunk-electronic/ada_training/blob/master/src/containers/demo/nested/nest_1.adb
Description:
Inside the procedure "get_line" the cursor "result" is assigned only
once (on match). Since there is no further match, in the course of the procedure, I assume that "result" is never changed. So the expected
output should be:
net: A
L1 S: 2.00000E+00 E: 3.00000E+00
L2 S: 2.00000E+00 E: 3.00000E+00
net: B
L2 S: 2.00000E+00 E: 3.00000E+00
L3 S: 2.00000E+00 E: 3.00000E+00
but the actual output is:
net: A
L1 S: 2.00000E+00 E: 3.00000E+00
L2 S: 2.00000E+00 E: 3.00000E+00
net: B
L2 S: 1.20000E+01 E: 1.30000E+01
L3 S: 7.47956E-39 E: 0.00000E+00 -- changes randomly
On Wednesday, April 19, 2023 at 9:09:48 AM UTC+2, Mario Blunk wrote:
Using a reference instead should fix this problem:
net : type_net renames nets.reference (key(n));
or (Ada 2012):
net : type_net renames nets(n);
Hello out there,
I've put together a demo to reproduce a strange behavior of a cursor.
https://github.com/Blunk-electronic/ada_training/blob/master/src/containers/demo/nested/nest_1.adb
Each call to `element(n)` returns a _copy_ of the element, which in
this case includes the enitre doubly linked list
(and since `net` is a renames of `element(n), you would have gotten multiple copies if you
had called `net` multiple times inside query net)
I wonder why at runtime no exception is raised.
How could I solve the problem ? Not using "rename" ? Using an aliased access type as John Barnes suggests in Ada2005 on page 275 ?
How could I solve the problem ? Not using "rename" ? Using an aliased access type as John Barnes suggests in Ada2005 on page 275 ?You have to avoid calling Element. Since you have a cursor, you can call Query_Element, which should pass the actual element to the procedure you supply.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 399 |
Nodes: | 16 (2 / 14) |
Uptime: | 65:12:25 |
Calls: | 8,355 |
Calls today: | 15 |
Files: | 13,159 |
Messages: | 5,893,953 |
Posted today: | 1 |