Menu

#566 Expression "a0e-30" is wrongly treated as a floating-point literal.

closed-fixed
None
2024-05-09
2024-04-25
Roy Qu
No

Astyle treats expressions like "a0e-30" as a floating-point literal, and can't insert spaces around "+".

The following program can't be correctly formatted.

int main() {
    int a0e = 10;
    float x = a0e-30;
    int y = 10 + 3;
}

Discussion

  • w-peuker

    w-peuker - 2024-04-25

    It's hard to reproduce the issue you described: You probably mixed "+" and "-" here and you don't tell us what options you are using. It's furthermore unclear if the code you show is before or after formatting and so it's not possible to understand how your expectations differ from the results you get. You better should have provided something like this:

    When formatting the following code with astyle version 3.4.14

    int main() {
        int a0e = 10;
        int a0e2 = 10;
        float x = a0e-30;
        float x2 = a0e1 - 30;
        float x3 = a0e+30;
        float x4 = a0e1+30;
        int x5 = a0e+30;
        int y = 10 + 3;
        int y2 = 10+3;
    }
    

    via the command line astyle --pad-oper < test.c > test-b.c
    (or astyle --pad-oper < test.cpp > test-b.cpp), I get this result:

    int main() {
        int a0e = 10;
        int a0e2 = 10;
        float x = a0e-30;
        float x2 = a0e1 - 30;
        float x3 = a0e+30;
        float x4 = a0e1 + 30;
        int x5 = a0e+30;
        int y = 10 + 3;
        int y2 = 10 + 3;
    }
    

    I found that there was no padding added around + and - in the cases where the variable name ended in e which led me to the conclusion that astyle treats these expressions as floating point literals despite the missing 0x prefix that allows hexadecimal floating point literals in C99 or C++17 respectively.

     

    Last edit: w-peuker 2024-04-25
    • Roy Qu

      Roy Qu - 2024-04-25

      Thank you for the clarification.

      I tried to format the following code with astyle 3.4.14:

      int main() {
          int a0e=10+30;
          float x=a0e-30;
      }
      

      via command astyle --style=java --indent=tab=4 --indent-switches --indent-namespaces --indent-preproc-block --min-conditional-indent=1 --pad-oper --pad-comma --pad-header < test.cpp > output.cpp.
      The result is:

      int main() {
          int a0e = 10 + 30;
          float x = a0e-30;
      }
      

      The operator '-' in "a0e-30" should be padded with spaces, but it's not.

       
  • André Simon

    André Simon - 2024-04-26
    • status: open --> open-accepted
    • assigned_to: André Simon
     
  • André Simon

    André Simon - 2024-05-09
    • status: open-accepted --> closed-fixed
     
  • André Simon

    André Simon - 2024-05-09

    Fixed in 3.4.15

     

Log in to post a comment.