0

I saw one question on similar lines Specify Array from Command Line Argument

Although my problem is bit different.

I have multiple files implementing arrays of same size (NOC_SIZE). My program has a default mode and a user mode (command line arguments). I gave the 'unsigned int NOC_SIZE = 16;' line in my code before the start of main function. In another header file I declared a struct (noc_package) with parameter 'static unsigned int NOC_SIZE;'. This header file in included in all files where ever required.

But in the files where I have declared an array (int arr[noc_package :: NOC_SIZE]) it gives an error saying array bound not an integer.

Can somebody suggest a way around this?

Thank you.

1 Answer 1

1

C++ doesn't support variable-length arrays.

You're better of using an std::vector instead:

std::vector<int> arr(noc_package::NOC_SIZE);
Sign up to request clarification or add additional context in comments.

15 Comments

True. But even after I provide the default size (which should be overridden, if required, by command line arguments) should not it work?
@Gurunath no, it shouldn't even work with the default size, since it appears it's not a compile-time constant.
I know you are right, but i thought there will be some solution to it. I can't use vector as the array I am creating is actually of predefined data structure (SystemC, HDL language based on C++). I even tried unsigned int NOC_SIZE = DEFAULT; with #define DEFAULT 16, but same result.
@Gurunath same result because what you're asking is impossible. I don't see how the array you want to create is a predefined data structure, since you're only just creating it...
If the "command line" that you are talking about is the command line of your executable, then no, you simply cannot. The executable has already been built with the array size preset. If it is the command line of the compiler, yes it is possible. Why do you think you cannot use a vector?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.