- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
While using PSOC5 i notice the device doesn't crash when I access out of bound array.
#define MAX_ARRAY 16
int array[MAX_ARRAY];
int a = [array MAX_ARRAY]; //array should be in range 0 - 15
I'm using PSOC creator with GCC compiler in debug mode.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi arenosoft,
I tested the code you are using on PSoC5.
#define MAX_ARRAY 16 /* Line 1 */
int array[MAX_ARRAY]; /* Line 2 */
int a = array [MAX_ARRAY]; /* Line 3 */
In Line 3, the Square Braces is used around 'MAX_ARRAY'.
The compilation gives a warning stating that variable 'a' is unused.
I executed the code in 'Debug' mode
In GCC, a variable declared as int is allocated 32bits, whereas in Keil it is allocated 16 bits.
When the memory window was observed, the variable 'a' was updated with a value which is subsequent to the location of the array declared.
As you have mentioned there is no error or warning message about the out of bound of the array during build.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thank you for your reply.
My sample code is not correct, yours is correct.
I found out that if I use optimization level (Release mode), GCC will give warning about subscript out of range.
GCC won't give warning if optimization turn off.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi arenosoft,
Thanks for sharing the info.