Menu

About Using "Alias"

jackjames
2023-12-22
2023-12-22
  • jackjames

    jackjames - 2023-12-22

    About Using "Alias"
    I'm turning a structure type variable with words and bytes into an array so I can handle and pass it easily.
    So in this array of bytes I have to insert byte and word values.
    With this statement you are given an error:
    Dim smeteo (20) as byte
    Dim Pressure As Word Alias smeteo (12), smeteo(13)
    Error: Size of alias variable (4) does not match number of locations (2).

    But doesn't a word variable take up two bytes?

     
    • Anobium

      Anobium - 2023-12-22

      Interesting ... I update the compiler last week to improve error messages when using Alias.

      But, this works here.

      #chip 16f88
      
      Dim smeteo(20) as byte
      Dim Pressure As Word Alias smeteo(12), smeteo(13)
      
      Pressure = 0xffff
      

      ASM looks correct. SMETEO is at RAM address 475 add 12 = 47. Pressure is at 487 & 488.

      ;********************************************************************************
      
      ;Set aside memory locations for variables
      SMETEO                           EQU     475          ; 0X1DB
      
      ;********************************************************************************
      
      ;ALIAS VARIABLES
      PRESSURE                         EQU 488
      PRESSURE_H                       EQU 487
      
      ;********************************************************************************
      

      What is your full program as I cannot reproduce?

       
      • jackjames

        jackjames - 2023-12-22

        My mistake!
        I had already sized the Pressure variable as long.
        When I renamed the names of the variables (which were in a struct, therefore NameStruct.NameVar) two variables were created with the same name, one long and the other word.
        The compiler rightly took the first one created as valid.
        Thanks to your help, seeing that you were fine with it, I investigated the very complex and long code and found the error.

         

Log in to post a comment.