Menu

#441 Replacements for SDCC macro

None
closed-fixed
None
5
2015-06-29
2015-06-18
No

When compiling using --std-sdccxx, sdcc defines a macro SDCC defined the conctenation of the version numbers (major, minor, p).
The macro name makes is incompatible with the C standard. And comparing it as an integer is problematic when any version number is above 9.
It should thus be deprecated, and replacements introduced.
I suggest:
__SDCC_VERSION, defined to MAJOR_VERSION.MINOR_VERSION
and
__SDCC_VERSION_MAJOR
__SDCC_VERSION_MINOR
__SDCC_VERSION_P

Philipp

Discussion

  • Frieder Ferlemann

    http://sourceforge.net/p/predef/wiki/Compilers/ has a huge collection.

    The GCC scheme seems not bad:)

    Greetings,

     
  • Ben Shi

    Ben Shi - 2015-06-19

    I like Borland C style,

    # define _SDCC_VERSION_MAJOR_ 3
    # define _SDCC_VERSION_MINOR_ 5
    # define _SDCC_VERSION_PATCH_ 0
    # define _SDCC_VERSION_ (((_SDCC_VERSION_MAJOR_) << 8) + _SDCC_VERSION_MINOR_)
    

    Because I thought int can be more efficient than float on 8-bit MCUs.

     

    Last edit: Maarten Brock 2015-06-29
    • Philipp Klaus Krause

      I assumed that users would mostly use the version at preprocessing time, so float vs. int wouldn't matter.
      But now I think we should provide just the macros for major, minor and p version, and users can make their own version macro, float or int from it as they like.

      Philipp

       
  • Philipp Klaus Krause

    • assigned_to: Philipp Klaus Krause
    • Group: -->
     
  • Philipp Klaus Krause

    Since I don't know how useful the patch version is, I left it out for now. Macros for major and minor version are in as of revision [r9261].

    Philipp

     

    Last edit: Maarten Brock 2015-06-29
  • Philipp Klaus Krause

    • status: open --> closed-fixed
     
  • Frieder Ferlemann

    Hi Philip,

    I feel this might not have been discussed thoroughly enough.

    The GCC macros (as per the link given above) are

    __GNUC__             Version
    __GNUC_MINOR__       Revision
    __GNUC_PATCHLEVEL__  Patch (introduced in version 3.0)
    

    They seem very reasonable to me and allow things like:

    #define __GNUC_VERSION__ (__GNUC__ * 10000 \
                              + __GNUC_MINOR__ * 100 \
                              + __GNUC_PATCHLEVEL__)
    

    or:

    #define __GNUC_VERSION__ ((__GNUC__ << 16)  \
                               + (__GNUC_MINOR__ << 8) \
                               + __GNUC_PATCHLEVEL__)
    

    (so it can easily be compared/printed as integer. In the second example even without using integer division for the deeply embedded systems)

    Why not follow the GCC scheme and use

    __SDCC__
    __SDCC_MINOR__
    __SDCC_PATCHLEVEL__
    

    As we use GCC's precompiler using GCC's convention seems a natural choice to me.

    The PATCHLEVEL is useful to have even if there is no immediate use for it.

    If e.g. a there's a bug with (or below) a specific patch level of SDCC which only surfaces later then a #warning (or a workaround) can be used without having to test #ifdef __SDCC_PATCHLEVEL__ first. (Without patchlevel the user could have to wait about a year until the ).

    Greetings,
    Frieder

    (hopefully Sourceforge doesn't garble the strings. If it does: my proposal is to exchange "GNUC" by "SDCC" in the Macros within the link given in my first post.)

     

    Last edit: Maarten Brock 2015-06-29
  • Philipp Klaus Krause

    I don't like that the names of the gcc macros do not clearly communicate what they are. And I don't like the name of the major version macro being inconsistent with the names of the other two.
    I don't mind adding another macro for the patchlevel. That should allow everything that the gcc macros do.

    Philipp

     
  • Maarten Brock

    Maarten Brock - 2015-06-29
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -2,10 +2,10 @@
     The macro name makes is incompatible with the C standard. And comparing it as an integer is problematic when any version number is above 9.
     It should thus be deprecated, and replacements introduced.
     I suggest:
    -__SDCC_VERSION, defined to MAJOR_VERSION.MINOR_VERSION
    +\_\_SDCC_VERSION, defined to MAJOR_VERSION.MINOR_VERSION
     and
    -__SDCC_VERSION_MAJOR
    -__SDCC_VERSION_MINOR
    -__SDCC_VERSION_P
    +\_\_SDCC_VERSION_MAJOR
    +\_\_SDCC_VERSION_MINOR
    +\_\_SDCC_VERSION_P
    
     Philipp
    
     
  • Maarten Brock

    Maarten Brock - 2015-06-29

    I suggest to add __SDCC_VERSION_PATCH as well.

     
    • Philipp Klaus Krause

      Implemented in revision #9273.

      Philipp

       
  • Frieder Ferlemann

    thanks, closed for me too.

    Buffer sizes with 20 bytes are a little on the short side. Please apply something like the appended patch.

     
    • Philipp Klaus Krause

      On the other hand, 32 seems plenty for now. I increased it to 32 in revision #9274.

      Philipp

       

Log in to post a comment.