-
Global Variables
Is it possible to declare global variables within a function?
I have an array MyArray[100,total_entries] but 'total_entries' is only initialized after the application starts running and its value depends on user input. Is it possible to do this without using malloc()? Im making low-level code and malloc() isnt available for use.
-
No, the only way to create some persistent memory with a variable size at run-time is to use malloc (or something like malloc).
-
if you know how much memory you'll need ahead of time, you can declare it as static.
-
A two-dimensional array where one side is "variable" requires that you either "guess" the maximum of the variabl side (say, "I don't think it will ever reach 100, so let's make it 200 to be sure"), or you allocate memory using "malloc" (or friends of malloc).
Depending on what you actually want to do, there may be several different ways to do this "best". If you give some more details of what you are actually trying to achieve, then there may be a chance that someone will also give better advice.
--
Mats