Forum Topic - Query in qnx: (3 Items)
   
Query in qnx  
If system has function foo below (in some lib) , what will be a problem
under QNX when some program calls this function, I am getting stack
overflow error..what is issue in this code..

Int foo(int a1, int a2)

{

int buf[9768];

int error = 0;

//

buf[365]  = a1;

buf[7194] = a2;

//
...doing something….
//

return error;

}
Please help me to understand in QNX context . Thanks in advance.
Attachment: HTML sf-attachment-mime33851 644 bytes
Re: Query in qnx  
The function is creating a 38KB object on the stack. Presumably you are calling the function with less than 38KB of free
 space left on the stack.
Re: Query in qnx  
Dear Michael,
Thank you for your response.

Finally the problem is stack overrides. Am I right? Please see below and
confirm.

It is re-entrant. But array is local to function so it will be in stack
segment. QNX has stack limit for thread in process.
Example: 9534 array of int, I.e  9k * 4 of stack size. So could be stack
overrides.
Instead allocate stack as 32bytes and sufficient for p1 and p2.

In some cases, it is worth the effort to optimize the stack, particularly
when the application has some frequent picks of stack activity (meaning
that a huge stack segment would be constantly mapped to physical memory).
We can watch the Memory Information view for stack allocation and inspect
code that uses the stack heavily. This usually occurs in two cases:
recursive calls (which should be avoided in embedded systems), and heavy
usage of local variables (keeping arrays on the stack

Thanks,
Ramu

On Sep 24, 2016 6:11 PM, "Michael Daniels" <community-noreply@qnx.com>
wrote:

> The function is creating a 38KB object on the stack. Presumably you are
> calling the function with less than 38KB of free space left on the stack.
>
>
>
> _______________________________________________
>
> General
> http://community.qnx.com/sf/go/post116875
> To cancel your subscription to this discussion, please e-mail
> general-toolchain-unsubscribe@community.qnx.com
>
Attachment: HTML sf-attachment-mime33855 1.98 KB