No announcement yet.

increment bug

  • Filter
  • Time
  • Show
Clear All
new posts

  • increment bug

    I discovered the following bug with incrementing on pointers.

    value++; works correctly and increments the pointer to the next memory field
    *value++; does not work, "error: statement has no effect" but should in my opinion increment the value the pointer is pointing too
    *value += 1; works fine

    Additionally there is a bug with the marked line/files for the error.
    I have several includes (7), the last 2 are these:
    // numpad functions
    #inherit "numpad.fnc"

    //serial communication
    #inherit "serial.fnc"

    On compiling the workshop gave me the "error: statement has no effect (line: 241 numpad.fnc)" message, but the error was in line: 241 serial.fnc.
    It also made the numpad.fnc file active and marked the line 241. I guess there is some bug in the file numeration.
    I only had the main file (.4dg), and the numpad.fnc and serial.fnc files open, all other includes were not opened at that time, the files also were opened in said order.

    This is actually pretty confusing if the workshop marks a line because of a compiling error and even if i outcomment the marked line i'll still get a error as the correct line but in a wrong file gets marked.

    edit: I'm using #platform "uLCD-43PT_GFX2"

  • #2

    *value++; does not work, "error: statement has no effect" but should in my opinion increment the value the pointer is pointing too

    4DGL is not C, it's not defined in the Language reference, so it's not supported.

    Thanks, for the report about the error being reported in the wrong include file. It's a bit of an odd one, as it usually gets it right. We'll look into it next time we are reviewing the compiler.


    • #3

      The compiler is actually reporting correctly and warning about a common mistake.

      The behaviour in 4DGL is actually the same as C, and *value++; will not work (as it will not work in C either)

      The ++ has equal precedence with the * and the associativity is right-to-left, so it will not function as an LVAL


      *item++;[list type=decimal][*]Post increment, get the post-incremented pointer address value to 'item' as a temporary[*]Dereference non-incremented pointer address (which is basically lost as the statement is officially an RVAL)Apply the incremented pointer address to 'item', 'item' now points to the next possible memory address.[/list type=decimal]
      So, nothing actually happens, thats why you get the warning.

      The correct way of doing it is:-


      The parenthesis alter the order of precedence, so now it works.

      note that the expression

      n := *value++;

      is quite ok because the n is loaded from the pointer before the pointer is incremented.