1

Unexpected behavior of atoi() function. It is working in some part of my code and returning 0 in other parts, I am using the following code in different parts of application to find the bug.

MPLAB X IDE V5.4, XC16 v1.61

 uint8_t result = 0;
 char test[] = {"33"};
  
 result = atoi(test);

     
Mike
  • 4,041
  • 6
  • 20
  • 37
Shahab
  • 11
  • 3
  • `atoi`return an `int`not a `uint8_t` – Mike Jan 20 '21 at 09:26
  • [Don't use `atoi()`.](https://stackoverflow.com/questions/17710018/why-shouldnt-i-use-atoi) It has absolutely no way to indicate an error, and if the input can't be represented as an `int`, using `atoi()` invokes undefined behavior. – Andrew Henle Jan 20 '21 at 10:15
  • Please show us a [example] that returns 0. – the busybee Jan 20 '21 at 13:13
  • After doing some debugging and comparing with old stable version the only thing I was able to figure out was the size of file. moving some code to other file solved the problem. strange. The Code Model was default [Small] may be this was the issue – Shahab Jan 20 '21 at 19:15
  • What happens if you change the Code Model? – Mike Jan 21 '21 at 05:50
  • Changing code model didn't resolve the issue. – Shahab Jan 22 '21 at 11:06

0 Answers0