• AVR Freaks

Hot!Initialization of static variables does not work with the XC8 PRO compiler

Page: 12 > Showing page 1 of 2
Author
elodirk
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2013/12/02 02:16:18
  • Location: 0
  • Status: offline
2019/12/06 03:30:53 (permalink)
0

Initialization of static variables does not work with the XC8 PRO compiler

Hello,
i am using the xc8 compiler in the version 1.20. The target controller is 18F46K80.
When i try to set a static variable int with a value, for example 4800, the start value is zero.
It does not matter to initialize the variable local or not local. But when i switch the compiler from PRO to standard, the variable is set to the correct value.
Is there a bug in the PRO-Version with initialising of variables?
Or is it possible to disable variable initialising by compiler setting?
 
 
#1

22 Replies Related Threads

    ric
    Super Member
    • Total Posts : 27968
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/06 05:54:41 (permalink)
    +1 (1)
    How are you checking this?
    If nothing ever uses that variable, then PRO mode will optimise it away, which it is perfectly entitled to do if that  has no effect on the function of your program.
     
     

    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
    elodirk
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2013/12/02 02:16:18
    • Location: 0
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/09 09:13:30 (permalink)
    0
    Hello ric,
     
    thanks for your response.
     
    I am using the variable to get a delay after reset.
    So this variable shall count down to zero. If it is zero a flag is set.
    This variable is used to get a second delay for an alarm.
    I have reduced the function in which the variable is used.
    At the three positions #A to #C he counter is loaded in the standard version correctly and the counter is not loaded, or loaded with zero in the PRO version.
    #3
    1and0
    Access is Denied
    • Total Posts : 10986
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/09 09:43:18 (permalink)
    +1 (1)
    elodirk
    i am using the xc8 compiler in the version 1.20.

    That was released over six years ago. Try updating. ;)
     
    #4
    JPortici
    Super Member
    • Total Posts : 1114
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: online
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/09 10:01:42 (permalink)
    0
    I don't think that 1.20 even supported static variables. I think static variables have been supported by 2.00 and newer, and in C99 mode only.
    #5
    1and0
    Access is Denied
    • Total Posts : 10986
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/09 10:16:02 (permalink)
    +2 (2)
    Jack_M
    I don't think that 1.20 even supported static variables. I think static variables have been supported by 2.00 and newer, and in C99 mode only.

    I doubt that. C89 has static storage too.
    #6
    JPortici
    Super Member
    • Total Posts : 1114
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: online
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/09 10:33:49 (permalink)
    0
    I know, but i remember having simillar issues prior to 2.00
    #7
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11930
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/09 12:36:32 (permalink)
    +3 (3)
    I don't think that 1.20 even supported static variables. I think static variables have been supported by 2.00 and newer, and in C99 mode only.

     
    That is complete nonsense.
    #8
    elodirk
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2013/12/02 02:16:18
    • Location: 0
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/11 01:28:40 (permalink)
    0
    The problem is not the static variable itself, but the initialization of it.
     
    I have tried the XC8 compiler V2.10 but the PRO-Mode is not working. But when i select optimization level 1 the variable is not set too. It starts with zero. In optimization level 0 the counter is set.
     
    But in Version 2.10 there is another problem with the priority of interrupts.
     
    #9
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3984
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/11 10:58:31 (permalink)
    0
    Does this work:
    int func(){
        static int x = 42;
        return x++;
    }


    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.
    #10
    elodirk
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2013/12/02 02:16:18
    • Location: 0
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/12 01:28:08 (permalink)
    0
    int func()
    {
      static int x = 42;
      return x++;
    }

     
    This function works correctly (starts with 42) in the standard mode of the compiler. In PRO mode it starts with zero.
    Compiler XC8 V1.20
     
    Compiler call in the PRO Version:
    "C:\Program Files (x86)\Microchip\xc8\v1.20\bin\xc8.exe" --pass1  --chip=18F46K80 -Q -G    --double=32 --float=32 --emi=wordwrite --opt=+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=pro -D__XC8__ -P -N255 --warn=0 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib   --output=-mcof,+elf "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"     -obuild/default/production/_ext/1766588332/DRTEST.p1 DRTEST.C "
     
    Linker call:
    "C:\Program Files (x86)\Microchip\xc8\v1.20\bin\xc8.exe"  --chip=18F46K80 -G -mdist/default/production/Rtest.X.production.map  -DXPRJ_default=default    --double=32 --float=32 --emi=wordwrite --opt=+asm,+asmfile,+speed,-space,-debug --addrqual=ignore --mode=pro -D__XC8__ -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib --output=-mcof,+elf "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"       -odist/default/production/Rtest.X.production.elf  build/default/production/_ext/1766588332/DrSioPIC.p1 build/default/production/_ext/1766588332/DRTEST.p1  build/default/production/_ext/1766588332/DR_EINH.p1 build/default/production/_ext/1766588332/drpid.p1 ..."    


    #11
    ric
    Super Member
    • Total Posts : 27968
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/12 01:41:31 (permalink)
    +1 (1)
    Do you have to stick with version 1.20?
    Microchip certainly are not going to do anything about it if it works ok in later versions.

    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!
    #12
    ric
    Super Member
    • Total Posts : 27968
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/12 01:41:31 (permalink)
    +1 (1)
    Do you have to stick with version 1.20?
    Microchip certainly are not going to do anything about it if it works ok in later versions.

    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!
    #13
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3984
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/12 08:53:03 (permalink)
    0
    It will have to be set manually:
    int test(int x){
        static int X;
     
        if(x) X=x; else X++;
        return X;
    }


    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.
    #14
    elodirk
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2013/12/02 02:16:18
    • Location: 0
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/18 05:19:06 (permalink)
    0
    Thank you for your response.
     
    I found a solution to use static initialization in the PRO-mode.
    When i change the configuration of the EBTR2 bit to disabled, the program is working correctly.
     #pragma config EBTR2 = OFF       // Table Read Protect 08000-0BFFF (Disabled)
    EBTR3 was disabled before.
    For security i also disabled EBTR0 and EBTR1.
     
     
    #15
    mlp
    boots too small
    • Total Posts : 946
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/18 07:40:10 (permalink)
    0
    elodirk
    When i change the configuration of the EBTR2 bit to disabled, the program is working correctly.

    And this is why you should show all your code when you ask a question.
    If we could have seen your config bits 2 weeks ago, your problem would have been solved 2 weeks ago.

    Mark (this opinion available for hire)
    #16
    1and0
    Access is Denied
    • Total Posts : 10986
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/18 08:58:16 (permalink)
    0
    mark.pappin
    And this is why you should show all your code when you ask a question.
    If we could have seen your config bits 2 weeks ago, your problem would have been solved 2 weeks ago.

    Years ago, I questioned whether the compiler takes into account the EBTRn (and WRTn) config bits when allocating code. This seems to show it does not consider the EBTRn bits. IMO, this is a compiler shortcoming (aka bug ;).
    #17
    mlp
    boots too small
    • Total Posts : 946
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/19 13:34:12 (permalink)
    0
    1and0
    a compiler shortcoming (aka bug ;)

    Absence of a feature is not a bug in the compiler unless the compiler is documented to do it and fails.
     
    You could reasonably argue that it's a bug in the compiler's specification and lobby for the feature to be added, but I don't fancy your chances unless you also pay for the developer time to implement that feature. :(

    Mark (this opinion available for hire)
    #18
    Jim Nickerson
    User 452
    • Total Posts : 6715
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/19 17:04:03 (permalink)
    0
    mark.pappin
    unless you also pay for the developer time to implement that feature. :(

    Do you think I would be permitted to  "pay" for the developer time to implement a feature ?
    #19
    NKurzman
    A Guy on the Net
    • Total Posts : 18850
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Initialization of static variables does not work with the XC8 PRO compiler 2019/12/19 17:53:11 (permalink)
    0
    JANickerson
    mark.pappin
    unless you also pay for the developer time to implement that feature. :(

    Do you think I would be permitted to  "pay" for the developer time to implement a feature ?

    Maybe in the Hi-Tech days.
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5