New compiler and structures

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

New compiler and structures

Post by Coccoliso » Tue Apr 22, 2014 9:39 am

Hello
I have noticed a difference in the treatment of arrays of structures between version 2.2.1.9 - 1.1.6.3 ICC and the one I have just updated.
Let me explain.
In a form I defined an array of private structures from which I get the individual values ​​contained in other modules via a public function.
The structure consists of a string and a byte.
Initialize the array in the main program and then visualize the different strings on the LCD .. obtained the values ​​obtained contain non-displayable characters.
This thing happens only after the upgrade.
All other strings not in structure are showed correctly on LCD.

Code: Select all

Module FIFO

Structure Utente
    Nome            As String
    Luce            As Byte
End Structure

    Const _MAX_CALL_POINTS = 16        

Private Dim UtStack( _MAX_CALL_POINTS ) As Utente 
Private Dim UtLastIN                    As Byte

Public Inline Sub UtPush(Nome As String, Luce As Integer)
    UtStack(UtLastIN).Nome = Nome 
    UtStack(UtLastIN).Luce = Luce                
    Inc(UtLastIN)
End Sub

Public Inline Function GetUTLabel(Index As Byte) As String 
    If Index <= Bound(UtStack) Then
        result =  UtStack(Index).Nome
    Else 
        result = ""
    End If    
End Function

Public Inline Function GetUTLight(Index As Byte) As Byte
    If Index <= Bound(UtStack) Then
        result =  UtStack(Index).Luce
    Else 
        result = $FF
    End If    
End Function

Private Sub Initialize()
    UtLastIN    = $00
End Sub

Initialize
Main program

Code: Select all

    ....
    FIFO.UtPush("1A",1)   ' 0
    FIFO.UtPush("2A",1)   ' 1
    FIFO.UtPush("3A",1)   ' 2
    FIFO.UtPush("1B",2)   ' 3
    FIFO.UtPush("2B",2)   ' 4
    FIFO.UtPush("3B",2)   ' 5
    FIFO.UtPush("1C",3)   ' 6
    FIFO.UtPush("2C",3)   ' 7
    FIFO.UtPush("3C",3)   ' 8
    FIFO.UtPush("1D",4)   ' 9
    FIFO.UtPush("2D",4)   ' 10
    FIFO.UtPush("3D",4)   ' 11
    FIFO.UtPush("1E",5)   ' 12
    .......
Other calling module

Code: Select all

Module VisStati

    Include "graphics.bas"
    Include "glcd.bas"
    Include "fifo.bas"
    dim sUT as String
    ...... 
 
    sUT = FIFO.GetUTLabel(2)
    If sUT <> "" Then 
      GLCD.WriteStr(0,0, sUT )  
    End If
    ......

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: New compiler and structures

Post by Jerry Messina » Tue Apr 22, 2014 10:17 am

I just tried this simple example using the fifo module you posted and it worked

Code: Select all

include "fifo.bas"
dim sUT as String

FIFO.UtPush("1A",1)   ' 0
FIFO.UtPush("2A",1)   ' 1
FIFO.UtPush("3A",1)   ' 2
FIFO.UtPush("1B",2)   ' 3
FIFO.UtPush("2B",2)   ' 4
FIFO.UtPush("3B",2)   ' 5
FIFO.UtPush("1C",3)   ' 6
FIFO.UtPush("2C",3)   ' 7
FIFO.UtPush("3C",3)   ' 8
FIFO.UtPush("1D",4)   ' 9
FIFO.UtPush("2D",4)   ' 10
FIFO.UtPush("3D",4)   ' 11
FIFO.UtPush("1E",5)   ' 12

sUT = FIFO.GetUTLabel(2)	// sUT = "3A"
sUT = FIFO.GetUTLabel(3)	// sUT = "1B"
sUT = FIFO.GetUTLabel(4)	// sUT = "2B"
but I did get a compiler warning

Code: Select all

Warning[] E:\test\fifo.bas 21 : Return string of function 'GetUTLabel' might not have been dimensioned
Perhaps you could try declaring the return length of "Function GetUTLabel(Index As Byte) As String" and see if that fixes things?

Code: Select all

Module FIFO

Const _STRING_SIZE = 6       

Structure Utente
    Nome            As String(_STRING_SIZE)
    Luce            As Byte
End Structure

Const _MAX_CALL_POINTS = 16       

Private Dim UtStack( _MAX_CALL_POINTS ) As Utente
Private Dim UtLastIN                    As Byte

Public Inline Sub UtPush(Nome As String, Luce As Integer)
    UtStack(UtLastIN).Nome = Nome
    UtStack(UtLastIN).Luce = Luce               
    Inc(UtLastIN)
End Sub

Public Inline Function GetUTLabel(Index As Byte) As String(_STRING_SIZE)
    If Index <= Bound(UtStack) Then
        result =  UtStack(Index).Nome
    Else
        result = ""
    End If   
End Function

Public Inline Function GetUTLight(Index As Byte) As Byte
    If Index <= Bound(UtStack) Then
        result =  UtStack(Index).Luce
    Else
        result = $FF
    End If   
End Function

Private Sub Initialize()
    UtLastIN    = $00
End Sub

Initialize

end module

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: New compiler and structures

Post by David Barker » Tue Apr 22, 2014 11:13 am

There is still a problem with string allocatio. Expected a new update later today.

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: New compiler and structures

Post by David Barker » Tue Apr 22, 2014 11:44 am

OK, could you try installing the latest update (2.2.2.1) and let me know if it corrects the problem for you.

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: New compiler and structures

Post by Coccoliso » Tue Apr 22, 2014 11:55 am

G R E A T !

Great job!
It all works perfectly now without changes to the original source ..

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: New compiler and structures

Post by David Barker » Tue Apr 22, 2014 1:38 pm

Thanks for letting me know it works OK...

Post Reply