I am working with cortex-m4 microcontroller from TI TM4C123GH6PM. I am trying to allocate the memory space by following c syntax
char *target; int size=10; target=(char *)malloc(size*sizeof(char)); //allocating size for string if(target==0)red; else green; free(target);
The line where I am trying to assign the allocated space address to the char pointer cause Reset Handler to trigger at line LDR R0, =SystemInit
Disassembly 0x0000090c BEAB 0xAB
commenting that line cause to glow red led, means rest of the lines are executing perfectly. Same with the calloc function. I don't have any idea about this error please help.
The size of the heap is usually described in startup_xyz.s
You should also check "Use MicroLIB"
"Yes red and green are macros and they work just fine."
Don't you see a problem with a #define'd symbol that on one hand doesn't tell what it does? And doesn't indicate that there is an expansion? And is used in a way where it looks like if there is zero side effect?
A statement that visually isn't a function call, and doesn't make an assign and doesn't include any operator with a side effect should not produce any side effect.
The following is an example of a meaningless statement, that doesn't make use of the value of a variable, and doesn't change the value - but in your code the same construct is expected to have a side effect and turn on the red LED (and possibly also turn off the green LED):
int red; red;
This code indicates that maybe something named "red" is turned on:
red = On;
and this code indicates that something named "red" might have become more red:
red++;
If "red" means "turn on the red LED" and "green" means "turn on the green LED" then the open question would be "how to turn off the red LED?" "how to turn off the green LED?" "how to turn off both the red and the green LED?" "how to know if 'red' also affects the green LED?" "how to know if 'green' also affects the red LED?" "how to know if the red LED is lit?" "how to know if the green LED is lit?" "will 'black' turn off just the red LED?" "will 'black' turn off just the green LED?" "will 'black' turn off both the red and the green LED?"
The cost to maintain code, and the number of bugs, is greatly affected by how easy it is to read and understand the code. So the shortest code is seldom the quickest code to produce - typing the code lines is a small part of designing software.
Note that a compiler implementation where "char" has 16 bits, would still have sizeof(char) == 1.
So sizeof(char) isn't 1 because the char is one octet large, but because "char" is the unit type for memory sizes.
So sizeof(double) doesn't tell the number of octets, but how many "char units" that is needed to store a double.
Problem has been resolved. What I needed to do was ALLOCATE HEAP SIZE. I defined the size of heap in startup file and its working perfectly as I wanted.
Thanks to all for their attention.