Announcement

Collapse
No announcement yet.

Possible Compiler Bug

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Possible Compiler Bug

    Just a heads up, possible small compiler bug.

    When creating a 2D array, the compiler seems to fill the first value with a non-zero value, even if I specify the array as 0 when initializing (outside of main).

    Once I place the array inside another array, it assigns a value to the location, the array assignment seems to be working fine.

    Not a big deal, as I can just set all my values to zero when first starting the program, but just thought I would forward the bug, if it is one.

    FYI: the array where this occurs in my code is the encoderValues array, at position encoderValues[0][0]. The rest of the indexes have values of 0, but this one has a value, always the same value, probably having to do with it's assigned memory location. Attached files uOLED128.4dg (12.2 KB)

  • #2


    Can you create a simple example that shows what you are saying?

    I have several possible interpretations in my head and I need to know which one to properly focus on.
    Mark

    Comment


    • #3
      I attached the code so I wouldn't have to have such a long post, but maybe this will help. I don't know what is causing the problem, so I left everything in there. At the bottom, when I call putnum(DEC,encoderValues[0][0]), I would expect to get a zero, but instead I get 341.#platform "GOLDELOX"
      #inherit "4DGL_16bitColours.fnc"
      #inherit "VisualConst.inc"
      #inherit "uOLED128Const.inc"
      #inherit "uOLED128comm.inc"
      #inherit "MyriadWebProMedium.inc"

      #constant SERIAL_BUFFER_SIZE 27 //54 character circular buffer
      #constant ENCODER_NAME_BUFFER_SIZE 7 //14 characters for encoder name (should be small length, as it's just the parameter name
      #constant PAGE_NAME_BUFFER_SIZE 19 //38 Characters for page (contains the

      #constant IDLE 0
      #constant INIT 1
      #constant SMALLARC 2
      #constant LARGEARC 3

      #constant SET_SECTOR_UOLED128_INIT $media_SetSector(0x0000, 0x0000)
      #constant SET_SECTOR_ARC_SMALL $media_SetSector(0x0000, 0x1681)
      #constant SET_SECTOR_ARC_LARGE $media_SetSector(0x0000, 0x4480)

      #DATA //Using the DATA block stores these variables in the CODE space, saving precious variable
      word pageColors //storage space needed for character buffers for pages
      CYAN,BLUE,DARKVIOLET,DEEPPINK,ORANGE,YELLOW
      #END

      var encoderNameBuffer0_0[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer0_1[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer0_2[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer0_3[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer0[4];

      var encoderNameBuffer1_0[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer1_1[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer1_2[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer1_3[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer1[4];

      var encoderNameBuffer2_0[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer2_1[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer2_2[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer2_3[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer2[4];

      var encoderNameBuffer3_0[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer3_1[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer3_2[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer3_3[ENCODER_NAME_BUFFER_SIZE];
      var encoderNameBuffer3[4];
      var encoderNames[4];

      var pageNameBuffer0[PAGE_NAME_BUFFER_SIZE];
      var pageNameBuffer1[PAGE_NAME_BUFFER_SIZE];
      var pageNameBuffer2[PAGE_NAME_BUFFER_SIZE];
      var pageNameBuffer3[PAGE_NAME_BUFFER_SIZE];
      var pageNames[4];

      var enocderPage0Values[2]; //Packed as [ 0xHighByte0 0xLowByte0, 0xHighByte1 0xLowByte1]
      var enocderPage1Values[2]; //With 0xLowByte0 = Encoder 0,0xHighByte0 = Encoder 1
      var enocderPage2Values[2]; // 0xLowByte1 = Encoder 2,0xHighByte1 = Encoder 3
      var enocderPage3Values[2]; //Same pattern for all pages ( saves us 8 words of memory..)
      var encoderValues[4];

      var mode;
      var activeFrame:= 0;
      var activePage:=0;
      var activeEncoder:=0;

      var serialBuffer[SERIAL_BUFFER_SIZE];

      func main()

      var char:=0;

      gfx_Set(SCREEN_MODE,PORTRAIT) ;
      while(!media_Init())
      putstr("Drive not mounted...");
      pause(200);
      gfx_Cls();
      pause(200);
      wend

      *encoderValues := [enocderPage0Values,enocderPage1Values,enocderPage2Values,enocderPage3Values];

      *encoderNameBuffer0 := [encoderNameBuffer0_0,encoderNameBuffer0_1,encoderNameBuffer0_2,encoderNameBuffer0_3];
      *encoderNameBuffer1 := [encoderNameBuffer1_0,encoderNameBuffer1_1,encoderNameBuffer1_2,encoderNameBuffer1_3];
      *encoderNameBuffer2 := [encoderNameBuffer2_0,encoderNameBuffer2_1,encoderNameBuffer2_2,encoderNameBuffer2_3];
      *encoderNameBuffer3 := [encoderNameBuffer3_0,encoderNameBuffer3_1,encoderNameBuffer3_2,encoderNameBuffer3_3];
      *encoderNames := [encoderNameBuffer0,encoderNameBuffer1,encoderNameBuffer2,encoderNameBuffer3];

      *pageNames := [pageNameBuffer0,pageNameBuffer1,pageNameBuffer2,pageNameBuffer3];

      com_Init(serialBuffer,SERIAL_BUFFER_SIZE*2,0);
      //setbaud(BAUD_500000);

      txt_FontID(MyriadWebProMedium); //Font used throughout, only needs to be set once
      txt_Opacity(TRANSPARENT);

      putnum(DEC,encoderValues[0][0]);


      /*reset(); //Have to call this to set encoder values to zero, for some reason complier is not assinging them to zero... compiler bug.

      setMode(INIT);
      var frame;
      media_SetSector(0x0000, 0x0000);
      */
      repeat
      /*
      frame := 0;
      repeat
      media_VideoFrame(0,0, frame++);
      until (frame == peekW(IMG_FRAME_COUNT));
      if(peekW(TIMER0)==0)
      drawMode(mode);
      pokeW(TIMER0,10);
      endif
      */


      //if( (char:=serin()) >= 0) processMessage(char);

      forever


      endfunc

      Comment


      • #4


        I was hoping for a simpler example so I could focus on it more easily, sorry. Now that I look at it more closely, I see it isn't that hard to follow.

        Hmm.

        There is no support for multidimensional arrays in 4DGL, so your code
        putnum(DEC,encoderValues[0][0]);
        is effectively
        putnum(DEC,encoderValues[0]);
        or the address of enocderPage0Values

        Perhaps what you meant to try was
        putnum(DEC,*encoderValues[0][0]);
        Which seems help the compiler understand what you are trying to do.
        Mark

        Comment

        Working...
        X