• AVR Freaks

Hot!Unexpected behavior of atoi() function.

Author
shahab71
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2021/01/19 03:52:17
  • Location: 0
  • Status: offline
2021/01/20 01:52:37 (permalink)
0

Unexpected behavior of atoi() function.

Hi All
 
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 of big application.
The Compiler shows no error or warnings. Any Ideas what am I doing wrong.
 
MPLAB X IDE V5.4, XC16 v1.61,
Device :PIC24J256GA406
 

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

#1

4 Replies Related Threads

    ric
    Super Member
    • Total Posts : 29861
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Unexpected behavior of atoi() function. 2021/01/20 14:16:04 (permalink)
    +1 (1)
    Can you supply a complete program that fails?
    In the snippet provided, if the "result" variable is never used, then it can get optimised away.
    Adding a debug "watch" on the variable does NOT count as "being used".
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 19146
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Unexpected behavior of atoi() function. 2021/01/20 16:34:29 (permalink)
    +2 (2)
    "It is working in some part of my code"  How are you determining this?
    #3
    Mysil
    Super Member
    • Total Posts : 4111
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: Unexpected behavior of atoi() function. 2021/01/20 18:51:57 (permalink)
    0 (2)
    Hi,
    atoi(...)   is Not a function specified in C standardization documents.
     
    It is a common name of INTERNAL tool within C compiler implementation.
    As such, it may behave differently  in different compiler libraries, with different compiler implementations,
    or with different compiler versions.
    It may also be integrating with other functions in the compiler library, in a way that is internal to the library implementation. 
    Compiler Library implementers, may do anything they want with atoi(...) and similar functions,
    including specifying it as static ( that means: internal, private).
     
    If atoi(...); function is specified with argument list in library documentation belonging to the compiler implementation and version in use, then it may be used as specified.
    If this is Not the case, then you are operating Outside of Specifications.
     
        Mysil
    #4
    shahab71
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2021/01/19 03:52:17
    • Location: 0
    • Status: offline
    Re: Unexpected behavior of atoi() function. 2021/01/21 06:59:17 (permalink)
    0
    Thanks guys 
     
    I think I accidently overwrite some part of memory using memcpy() command and was able to fix it.
     
    Shahab
    #5
    Jump to:
    © 2021 APG vNext Commercial Version 4.5