Bug 929 - nms-p2p-nix.cc uses variable length array
nms-p2p-nix.cc uses variable length array
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: examples
ns-3-dev
All All
: P3 normal
Assigned To: Josh Pelkey
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-05-30 22:52 EDT by Quincy Tse
Modified: 2011-08-10 12:39 EDT (History)
2 users (show)

See Also:


Attachments
Proposed patch. (5.01 KB, patch)
2010-05-31 01:19 EDT, Quincy Tse
Details | Diff
alternative patch using nested new[] (6.96 KB, patch)
2010-10-26 22:56 EDT, Quincy Tse
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Quincy Tse 2010-05-30 22:52:46 EDT
nms-p2p-nix.cc uses variable length array, which cannot be compiled using some compilers (especially strict standards-compilent compilers like clang). Variable length array is part of C99 but does not comply with C++ standards (not in C++98, rejected for C++0x).
Comment 1 Quincy Tse 2010-05-30 22:53:32 EDT
Tried to cc the bug to original author, but the author is not registered on bugzilla.
Comment 2 Quincy Tse 2010-05-31 01:19:31 EDT
Created attachment 901 [details]
Proposed patch.

Proposed patch attached. Quite an ugly way to go about it (making 2D/3D array classes so that the main logic code doesn't have to change, but i can't see an easy way around it)

Haven't tested it yet because the test runs too long on my slow computer (even the original code take very long). I don't expect behaviours to have changed, but may have memory leaks due to the new[] operators.
Comment 3 Josh Pelkey 2010-08-10 22:48:33 EDT
(In reply to comment #2)
> Created an attachment (id=901) [details]
> Proposed patch.
> 
> Proposed patch attached. Quite an ugly way to go about it (making 2D/3D array
> classes so that the main logic code doesn't have to change, but i can't see an
> easy way around it)
> 
> Haven't tested it yet because the test runs too long on my slow computer (even
> the original code take very long). I don't expect behaviours to have changed,
> but may have memory leaks due to the new[] operators.

Do you think it would work if you used 2d and 3d std::vectors instead of creating these new classes and messing with dynamic arrays?

example: std::vector<std::vector<NodeContainer> > nodes_net0[nCN][3]
Comment 4 Quincy Tse 2010-08-11 01:28:34 EDT
(In reply to comment #3)
> Do you think it would work if you used 2d and 3d std::vectors instead of
> creating these new classes and messing with dynamic arrays?
> 
> example: std::vector<std::vector<NodeContainer> > nodes_net0[nCN][3]

Haven't worked with NS3 for a while now (I'm spending time analysing my data) - from memory, I chose not to use vector because the lengths are not fixed. There'll also need to be code to initialise the outside vectors. (I suppose we can use the constructor taking in default variable, but the code calling that constructor will look awful when we're looking at more than a couple of dimensions.)
Comment 5 Quincy Tse 2010-10-26 22:56:54 EDT
Created attachment 1006 [details]
alternative patch using nested new[]
Comment 6 Mathieu Lacage 2011-08-10 12:39:35 EDT
(In reply to comment #5)
> Created attachment 1006 [details]
> alternative patch using nested new[]

I read patch 2 and was about to suggest doing what you did in patch 1. applied patch 1 as obvious.

changeset: a26626a4f5bf