Menu

#578 Pointer dereferences and addresses are formatted as operators

open
nobody
None
2025-05-12
2024-08-06
No

Possibly related to #572 and/or #573.

Occurs using astyle version 3.5.2 on both Ubuntu 24.04 and Windows 10.

When using options --pad-oper and --align-pointer=type (and --align-reference=type, although as I understand it, that's unnecessary if using --align-pointer=type), pointer dereferences and addresses are formatted as if they were multiplication or logical AND operators. For instance:

int* ptr;
*ptr = 10;

int x;
int* ptr2 = &x;

foo(&x, *ptr);

becomes

int* ptr;
* ptr = 10;

int x;
int* ptr2 = & x;

foo( & x, * ptr);

Full .astylerc attached.

1 Attachments

Discussion

  • RyzenFromFire

    RyzenFromFire - 2024-08-06

    Note: just tested without --pad-oper and the behavior described does not occur. Using the same settings except --pad-oper, the first codeblock remains unchanged.

    Let me know if you need any more info.

     
  • André Simon

    André Simon - 2024-08-11

    Should be fixed in 3.6.0

     
    • RyzenFromFire

      RyzenFromFire - 2024-08-20

      Apologies for the delayed response. This issue does not yet seem to be fixed, or at least it does not behave as I expected. The behavior is definitely different now, as follows - with the same .astylerc as before, now running v3.6.0:

      This:

      // this is the format that I expect based on my .astylerc
      int* ptr;
      *ptr = 10;
      
      int x;
      int* ptr2 = &x;
      
      foo(&x, *ptr);
      

      is formatted to this:

      int* ptr;
      * ptr = 10; // a space was added after *
      
      int x;
      int* ptr2 = &x;
      
      foo(&x, *ptr);
      

      which is strange.

      More interestingly, this:

      int* ptr;
      * ptr = 10;
      
      int x;
      int* ptr2 = & x;
      
      foo( & x, * ptr);
      

      is formatted to this:

      int* ptr;
      * ptr = 10;
      
      int x;
      int* ptr2 = & x;
      
      foo(& x, * ptr); // a space was removed after (
      

      when I would expect this:

      int* ptr;
      *ptr = 10;
      
      int x;
      int* ptr2 = &x;
      
      foo(&x, *ptr);
      

      I will also note that spaces between the type keyword and the asterisk are correctly removed. Also, again, removing the --pad-oper argument leaves both examples unchanged.

      Thanks for your work.

       

      Last edit: RyzenFromFire 2024-08-20
  • André Simon

    André Simon - 2024-09-08

    The padding within parens was fixed in 3.6.1. Others need some special handling.

     
  • Eugene Sandulenko

    The problem with * ptr = 10; is still present in 3.6.9

     

    Last edit: Eugene Sandulenko 2025-05-12

Log in to post a comment.