Hi, I created a magic square program to allow for a variable input of an odd value. However, I am getting the error
ISO C++ forbids variable-size array `magic' for line 9. If someone could please give me a nudge in the right direction to resolve it, that would be great.
Dynamic allocations are dangerous I heared e.g. in applications for airplanes. The risk is too high for an unexpected exception of low memory. Therefor the developer of such apps avoid using dynamic memory allocations and use instead static reserved memory allocation.
In your case what do you think about the idea to reserve a maximum array and delimit the users input to this maximum borders?
Anyone who uses C++ in a life-critical system or who designs a life-critical system in such a way that human input is passed directly to it without first being sanitized by a less-critical component should probably be fired, anyway.
In your case what do you think about the idea to reserve a maximum array and delimit the users input to this maximum borders?
It's a waste of resources and effort. A process that deliberately allocates more memory than it needs in a multitasking system is misbehaving.
The risk is too high for an unexpected exception of low memory.
Aside from experienced and capable software system designers who could foresee and handle this, I think Bertrand Meyer and design by contract followers would have a lot to say to counter that bald statement.
An unexpected exception error almost seems to be a contradiction in terms unless it means someone ripped the case open and stole some RAM. Even then if there is a reasonable expectation that such an exceptional event could occur the owners could perhaps tie a vicious guard dog to the box. :)
I heard additionally that such apps of life-critical system are running twice (or more times) and a judge component compares the results of the calculations.
However what if the half of the results are "false" (caused by damage memory) and the other half are "true" or the judge component is knocked out?
Then there is only one option left: plug in and pray! ^^
Security is an illussion like bug-free applications or perfect design.