• AVR Freaks

Hot!XC16 strtol, strtof, strtod missing.

Author
Severino
New Member
  • Total Posts : 23
  • Reward points : 0
  • Joined: 2014/04/30 01:50:28
  • Location: 0
  • Status: offline
2019/10/14 03:58:25 (permalink)
0

XC16 strtol, strtof, strtod missing.

MPLABX v5.25, XC16 v1.41:

strtol, strtof, strtod are missing. In the related "16-Bit Language Tools Libraries Reference Manual" (DS50001456K) they are not listed any longer, but used to up to XC16 v1.32 or so. (document DS50001456J).

In stdlib.h they are declared conditionally only if the macro __C30_VERSION__ is defined:
#if defined(__C30_VERSION__)
extern double atof(const char *);
extern float strtof(const char *, char **);
extern double strtod(const char *, char **);
 
...
 

Earlier versions of MPLAB X seemed to define that macro also for XC16.
 
Also the editor in the current MPLAB X (5.25) underlines strtod and atof in red and I get a hint on the left of the code line: 
unable to resolve identifier

Strange is that the code compiles and links regardless of that.
 
Could an XC16 expert please explain me why they are missing?
Thanks a lot.
post edited by Severino - 2019/10/14 04:04:20
#1

14 Replies Related Threads

    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3315
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: XC16 strtol, strtof, strtod missing. 2019/10/14 04:36:24 (permalink)
    0
    Try sprintf instead although it takes up a lot of space.
     
    If you look in the include legacy directory you will see:
     
    stdlib.h
     
    It's not the same file as the one you are looking at.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #2
    Severino
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2014/04/30 01:50:28
    • Location: 0
    • Status: offline
    Re: XC16 strtol, strtof, strtod missing. 2019/10/14 05:48:53 (permalink)
    0
    Hi Gort2015
     
    Thanks for your reply. Whether I check "use legacy libc in the project properties, XC16 (global Options) or I leave it unchecked, the red unterlining is still there. What confuses me is that if I Ctrl-click on
     
    #include <stdlib.h>

    always the stdlib.h from the include folder opens, never the one from the lega-c subfolder.
    And I still wonder why these functions have been removed from the manual, without mentioning them in the revision history.
    One more thing: could you please explain what sprintf would help in this context?
    Thanks
    #3
    pcbbc
    Super Member
    • Total Posts : 1373
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: XC16 strtol, strtof, strtod missing. 2019/10/14 05:57:25 (permalink)
    +1 (1)
    The underlining in MPLAB doesn't always (read a lot of the time!) work correctly.
    What matters is if your project builds, not what is underlined.
    If you still have underlining clean, close, reopen and rebuild your project.
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 17964
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: XC16 strtol, strtof, strtod missing. 2019/10/14 06:02:57 (permalink)
    +2 (2)
    The incorrect red squiggly underlines are a long term problem with MPLabX. Ignore them. Try compiling, and see if the compiler generates error messages.
    Printf() would not help scanf() would.

    Or you could google for the functions code.
    Or write them you self. They are not that difficult.
    #5
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3315
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: XC16 strtol, strtof, strtod missing. 2019/10/14 06:23:36 (permalink)
    0
    Google, "sprintf".

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #6
    Severino
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2014/04/30 01:50:28
    • Location: 0
    • Status: offline
    Re: XC16 strtol, strtof, strtod missing. 2019/10/14 06:31:51 (permalink)
    0
    Thanks NKurzman,
    Probably Gort2015 meant sscanf() instead ot sprintf().
    Of course there are alternatives and workarounds, I simply don't understand why Microchip has removed some functions that existed before without any comment.
    And I wonder how the compiler decides where to look for the #include <> as in the project properties I haven't found any paths. I found the "C include dirs" but it is empty and everything builds, so there must be some hidden defaults and these don't match MPLAB X' code assistance settings, if there are any, otherwise Ctrl-Click on the include file name would open the correct one.
    #7
    Severino
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2014/04/30 01:50:28
    • Location: 0
    • Status: offline
    Re: XC16 strtol, strtof, strtod missing. 2019/10/14 07:39:26 (permalink)
    0
    Nice to know:
    Using MPLAB X v5.15 with the very same XC16 v1.41 the red underline and the hint are not shown. Ctrl-Click on the
    #include <stdlib.h>

    open the correct file (include/lega-c/stdlib.h).
    So this "behaviour" seems to be due to MPLAB X.
    Still wondering why Microchip removed the strtol, strtof, strtod functions from the manual.
     
    #8
    Mysil
    Super Member
    • Total Posts : 3428
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: online
    Re: XC16 strtol, strtof, strtod missing. 2019/10/14 08:50:14 (permalink)
    +1 (1)
    Hi,
    strtol, strtof, strtod and several similar functions are internal tools used to implement sprintf and sscanf 
    in some implementations of the C libraries.
    When C programming language have been standardized, several of these internal helper functions have been deliberately omitted from the required list of standard library functions.
    One of the reasons for this, may be that different compilers have been observed to have different ordering of argument list.
    Other reason may be that they may no longer be used in the actual implementation of the compiler library.
     
    When Microchip is trying to make the compiler more strictly conforming to the official standard,
    they may have tried to remove functions that are not required from the standard header files.
    This may also depend on whether these functions are actually needed to support the features they were once supposed for.
     
    For the people writing and maintaining compiler and libraries, there is a never-ending balance between making a compiler that conform strictly to the official standard, or supporting past mistakes and old bad habits.
    Often, they end up with IDE selections and compiler command line options, to select what extensions to make available.
     
        Mysil
    post edited by Mysil - 2019/10/14 08:54:05
    #9
    1and0
    Access is Denied
    • Total Posts : 9920
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: XC16 strtol, strtof, strtod missing. 2019/10/14 09:16:28 (permalink)
    +1 (1)
    The XC16 C compiler is an ANSI C compliant compiler conforming to the C89 Standard, with some C99 features supported.  As I understand it, strtod() and strtol() are since C89 and strtof() is C99.

    C89/C90 Standard (ISO/IEC 9899:1990):
    • 4.10.1.4  The strtod function
    • 4.10.1.5  The strtol function

    C99 Standard (ISO/IEC 9899:1999):
    • 7.20.1.3  The strtof function
    post edited by 1and0 - 2019/10/14 09:18:13
    #10
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3315
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: XC16 strtol, strtof, strtod missing. 2019/10/14 09:52:33 (permalink)
    0
    Probably Gort2015 meant sscanf() instead ot sprintf().
    I know.
     
    The logic is quite simple:  atof
     
    0. Check string is null.
    1. read the number as integer or long integer.
    2. Mark the point where the period occurred.   6 .. (strlen 9 - 6 - 1) = 2
    3. Stop on bad character, overflow or eol.
    4. Divide 12345678 by 100 since 2 places from eol.
     
     
    "123456.78" to 123456.78
     
     
    post edited by Gort2015 - 2019/10/14 09:54:55

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #11
    Severino
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2014/04/30 01:50:28
    • Location: 0
    • Status: offline
    Re: XC16 strtol, strtof, strtod missing. 2019/10/15 00:54:17 (permalink)
    0
    Thanks everybody for trying to enlighten me.
    I still don't understand why the functions have been removed without comment, especially if they are part of C89, according to 1and0's post.
    Regarding to an easy own implementation I just say: DRW.
    #12
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3315
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: XC16 strtol, strtof, strtod missing. 2019/10/15 01:39:49 (permalink)
    0
    You work for Micrografx ?

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #13
    Severino
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2014/04/30 01:50:28
    • Location: 0
    • Status: offline
    Re: XC16 strtol, strtof, strtod missing. 2019/10/15 02:05:41 (permalink)
    0
    You work for Micrografx ?

    No, why should I?
    #14
    crosland
    Super Member
    • Total Posts : 1674
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: XC16 strtol, strtof, strtod missing. 2019/10/15 02:07:54 (permalink)
    0
    pcbbc
    If you still have underlining clean, close, reopen and rebuild your project.

    Or, more simply, right click on the project -> Code Assistance -> Reparse Project
     
    Works every time for me :)
    #15
    Jump to:
    © 2019 APG vNext Commercial Version 4.5