• AVR Freaks

Hot!Error 1402 - Depends on array size (or struct vs array), XC8 2.20

Author
sjb741
Super Member
  • Total Posts : 834
  • Reward points : 0
  • Joined: 2010/01/25 08:45:39
  • Location: 0
  • Status: offline
2020/06/18 03:19:59 (permalink)
0

Error 1402 - Depends on array size (or struct vs array), XC8 2.20

The attached example throws an Error 1402 when the size of the array
   uint8_t presets
is 4. The error only happens for array size 4.


An even simpler example is the second project. Size 82 gives the error but 81, 83 are OK. This is a summary
   typedef __eeprom uint8_t *EEPROM_PTR; 
   typedef struct
   {
      uint8_t a[80]; //Error 1402 if size = 82, OK if size=81
   }TnvLayout;
   //typedef uint8_t TnvLayout[82]; //OK for size 82
//-------------- RAM Object ---------------
TnvLayout FACTORY;
//-------------- EEPROM Object ---------------
__eeprom TnvLayout allEeprom;
EEPROM_PTR gEEPersistentData = (EEPROM_PTR)(&allEeprom); //"error: (1402) a pointer to eeprom cannot also point to other data types"

 
post edited by sjb741 - 2020/06/19 06:06:58
#1

10 Replies Related Threads

    sjb741
    Super Member
    • Total Posts : 834
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re: Error 1402 - Depends on array size (or struct vs array), XC8 2.20 2020/06/18 09:03:32 (permalink)
    +1 (1)
    I found that Version 2.20 Release Notes state that a bug relating to this error message was fixed in v2.10:
    http://ww1.microchip.com/downloads/en/DeviceDoc/xc8-v2.20-full-install-release-notes-PIC.pdf
    #2
    NKurzman
    A Guy on the Net
    • Total Posts : 18785
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Error 1402 - Depends on array size (or struct vs array), XC8 2.20 2020/06/18 09:08:02 (permalink)
    +1 (1)
    What Chip?
    how much eeprom does it have?
    C90 Mode or C99 Mode?
    #3
    sjb741
    Super Member
    • Total Posts : 834
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re: Error 1402 - Depends on array size (or struct vs array), XC8 2.20 2020/06/19 04:01:13 (permalink)
    0
    Chip = 16F1825
    EEPROM size = 256 Bytes
    Uses C99 libs - is that the same as 'mode'?
     
    #4
    sjb741
    Super Member
    • Total Posts : 834
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re: Error 1402 - Depends on array size (or struct vs array), XC8 2.20 2020/06/19 04:10:07 (permalink)
    0
    Got it down to a single file, a few lines.
    • There is no error if the definitions for one (or both) of TnvLayout1, TnvLayout2 are changed to a simple array.
    • Removing the RAM variable makes the error go.
    • The relative ordering of declaration of RAM vs EEPROM objects does not affect results.
    • It does not affect matters to declare the EEPROM object (and associated, initialised pointer) in a separate file.
     
    //Investigating Error 1402 in XC8 2.20. Chip = 16F1825.
    #include "xc.h"
    #include "stdint.h"

    typedef __eeprom uint8_t *EEPROM_PTR;
    typedef struct
    {
       uint8_t a[82]; //Error 1402 if size = 82, OK if size=81
    }TnvLayout;
    //typedef uint8_t TnvLayout[82]; //OK for size 82

    typedef struct
    {
       uint8_t a[82];
    }TnvLayout2;
    //typedef uint8_t TnvLayout2[82];

    __eeprom TnvLayout allEeprom;//-------------- EEPROM Object ---------------
    EEPROM_PTR gEEPersistentData = (EEPROM_PTR)(&allEeprom); //"error: (1402) a pointer to eeprom cannot also point to other data types"
    TnvLayout2 FACTORY;//-------------- RAM Object ---------------

    void main(void)
    {
     for(;;)
     {
     }//for(;;)
    }//main

     
    post edited by sjb741 - 2020/06/19 04:17:30
    #5
    sjb741
    Super Member
    • Total Posts : 834
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re: Error 1402 - Depends on array size (or struct vs array), XC8 2.20 2020/06/19 06:18:35 (permalink)
    +1 (1)
    Here is something really wierd...
    • If the RAM & EEPROM object have different sizes then it compiles OK.
    • If they have the same size, it compiles OK only when that size < 82
    If the situation above had a special feature for size <81 (rather than size <82), I'd say it might relate to banked memory.
    Anyway:
    • RAM [90], EEPROM [91] is fine
    • RAM [90], EEPROM [90] is error
    • RAM [81], EEPROM [81] is fine
    • RAM [74], EEPROM [74] is fine
     
     
    In my actual project, I added a bogus field to a structure that is otherwise identical to that I actually want. I use one structure type for RAM, the other for EEPROM. I should be able to ignore the extra field. That change does permit a sucessful compile - although I am of course uneasy about this.
       typedef struct //Combining into ONE struct to guarantee object sequence in EEPROM
       {
          TpwmCfg pwm0s[N_CONFIGS];
          TpwmCfg pwm1s[N_CONFIGS];
          uint8_t presets[N_CONFIGS];
          uint8_t BODGE_ERR_1402; //Simply to prevent an Error 1402
       }TnvLayout1;

       typedef struct
       {
          TpwmCfg pwm0s[N_CONFIGS];
          TpwmCfg pwm1s[N_CONFIGS];
          uint8_t presets[N_CONFIGS];
       }TnvLayout;

     
     
    post edited by sjb741 - 2020/06/19 08:17:05
    #6
    mad_c
    Super Member
    • Total Posts : 1243
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re: Error 1402 - Depends on array size (or struct vs array), XC8 2.20 2020/06/21 14:19:26 (permalink)
    +2 (2)
    Hi,
     
    I haven't look at you complete program, but what you are suggesting does not sound that unusual for XC8. The compiler tracks address assignments to pointers and then how these targets propagate through the program. As the compiler has to make certain assumptions, it can often have more targets that will occur in the program at runtime. When two structures are of different sizes, the compiler knows that a pointer cannot point to both, but there might be instances where making different structures the same size will see that both get added to a pointers target list.
     
    Jeff.
    #7
    sjb741
    Super Member
    • Total Posts : 834
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re: Error 1402 - Depends on array size (or struct vs array), XC8 2.20 2020/06/27 09:46:17 (permalink)
    +1 (1)
    Hi Jeff
     
    Thank you for looking at this. I am unsure if this query is resolved, maybe I just do not understand -
     
    mad_c: The compiler tracks address assignments to pointers...
    sjb741: In the single file example there is a single assignment in the entire program:
          EEPROM_PTR gEEPersistentData = (EEPROM_PTR)(&allEeprom);

    mad_c: ...and then how these targets propagate through the program.
    sjb741: There is (almost) no program. Just for(;;);

    mad_c: it can often have more targets that will occur in the program at runtime
    sjb741: I can't see how that can apply in this example though?
     
    Regards
    Stephen
    #8
    mlp
    boots too small
    • Total Posts : 934
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: Error 1402 - Depends on array size (or struct vs array), XC8 2.20 2020/06/28 09:26:04 (permalink)
    +2 (4)
    sjb741
    Hi Jeff
     
    Thank you for looking at this. I am unsure if this query is resolved, maybe I just do not understand -

    Jeff had not looked at your code.
    Jeff was describing how the compiler handles pointers.
    Jeff wrote much of the code that handles pointers within the compiler, so he knows intimately how that works.
     
    If your code does not have the characteristics he describes as relevant, then perhaps you should submit a ticket with a complete sample program that demonstrates the problem and a description of what you expect to see and what you actually see.

    Mark (this opinion available for hire)
    #9
    mad_c
    Super Member
    • Total Posts : 1243
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re: Error 1402 - Depends on array size (or struct vs array), XC8 2.20 2020/06/28 14:55:25 (permalink)
    +1 (1)
    Hi Stephen,
     
    I took a look at your cut-down example, and it is as I suspected, although this is a very annoying example of what I explained. I believe that the error is being triggered early on in the build process, when the exact call graph has not been ascertained and the compiler is making a lot of assumptions. If you modify either of the structures so they have different forms (either changing the array size or adding another member) then the final pointer reference graph present in the assembly listing file correctly shows that there is only one target to gEEPersistentData, but initially, that probably isn't the case.
     
    I would send in a support request so that this can be logged. In the mean time, making the two structures different in any way will not trigger the error.
    #10
    sjb741
    Super Member
    • Total Posts : 834
    • Reward points : 0
    • Joined: 2010/01/25 08:45:39
    • Location: 0
    • Status: offline
    Re: Error 1402 - Depends on array size (or struct vs array), XC8 2.20 2020/06/30 00:26:12 (permalink)
    0
    I've added a ticket now. Case Number :  00527214
    #11
    Jump to:
    © 2020 APG vNext Commercial Version 4.5