Menu

#573 Incorrect indent when multiple pointers are declared in a single line

closed-fixed
None
2024-08-11
2024-05-24
No

This

_Ty* pRCol, *pGCol, *pBCol;

get formatted as

_Ty* pRCol, * pGCol, * pBCol;

at least since version 3.4.0, but not in 2.2.5

Something similar happens with struct declarations:

typedef struct _A
{
    ULONG foobar;
} A, *PA;

becomes

typedef struct _A
{
    ULONG foobar;
} A, * PA;

I think this is affected by the option

--align-pointer=type

but no matter which version I use, some parts (not always the same) of the code get formatted weird. I will happily provide more information if needed. Tell me whatever would help. Thanks!

Discussion

  • w-peuker

    w-peuker - 2024-05-29

    I would suggest that you reconsider this issue carefully. In my opinion, the style of formatting you want to preserve is extremely confusing. It puts you right between two common conventions:

    1. Always having the asterisk next to the name, so pointers are easy to recognize on a line with multiple variable declarations. Here the option --align-pointer=name makes the most sense.
    2. To have the asterisk next to the type because you always declare variables line by line anyway. In this context --align-pointer=type is a useful option.
     

    Last edit: w-peuker 2024-05-29
  • Stefan Battmer

    Stefan Battmer - 2024-05-29

    You certainly have a point here! I agree that the first example I brought up is a result of sloppy declaration/coding looking at it now! The 2nd one (the typedef with the struct) however is what I guess M$ introduced in their headers and which I therefore would consider being common practice, which has been copied a million times since then. Anyway: I agree that this is a problem, that needs to be solved elsewhere (meaning my code base for example;-) ). Thanks for the eye-opener!

     
    • w-peuker

      w-peuker - 2024-05-30

      Thanks for the reply which opened my eyes about the second case: typedef can indeed be “chained”, and I overlooked this because I'm mostly working in C++ where struct always introduces a type (no typedef needed) and references and smart pointers make pointer types disappear in the code base.

      So, the issue can be refined to something like: the option --align-pointer=type should only be applied to cases where pointer type and name are present around the * (the same would apply to --align-reference=type and &).

      Does this make sense? Also to you @saalen?

       
      • Stefan Battmer

        Stefan Battmer - 2024-05-30

        That sounds phenomenal and makes perfect sense!

         
        • André Simon

          André Simon - 2024-06-06

          The version 3.5 should improve --align-pointer=type as duscussed.

           
  • André Simon

    André Simon - 2024-06-03

    I am looking into this. The behaviour was changed to be more consistent, but in these cases it looks wrong.

     
  • André Simon

    André Simon - 2024-06-03
    • status: open --> open-accepted
    • assigned_to: André Simon
     
  • André Simon

    André Simon - 2024-08-11
    • status: open-accepted --> closed-fixed
     

Log in to post a comment.

Monday.com Logo