Skip to content

Allow indenting preprocessor macros? #1006

@matthijskooijman

Description

@matthijskooijman

While developing #997, I wrote some complicated and nested preprocessor statements. I originally tried making them clearer by applying indents, but that was not allowed by the astyle checks, so I removed them again. Now I wonder, should this astyle rule maybe be changed to allow (even if not require) indenting preprocessor directives?

e.g. consider:

#if defined(USBD_ATTACH_PIN)
#define USBD_PULLUP_CONTROL_PINNAME digitalPinToPinName(USBD_ATTACH_PIN)
#define USBD_DETACH_LEVEL !(USBD_ATTACH_LEVEL)
#elif defined(USBD_DETACH_PIN)
#define USBD_DETACH_PINNAME digitalPinToPinName(USBD_DETACH_PIN)
#define USBD_ATTACH_LEVEL !(USBD_DETACH_LEVEL)
#elif !USBD_HAVE_INTERNAL_PULLUPS
/* When no USB attach and detach pins were defined, and the USB module
 * also does not have any builtin pullups, assume there is a fixed
 * external pullup and apply the D+ trick. */
#if defined(USE_USB_HS_IN_FS)
#define USBD_PULLUP_CONTROL_PINNAME USB_OTG_HS_DP
#elif defined(USB_OTG_FS)
#define USBD_PULLUP_CONTROL_PINNAME USB_OTG_FS_DP
#else /* USB */
#define USBD_PULLUP_CONTROL_PINNAME  USB_DP
#endif
/* Detach by writing LOW, but leave floating instead of writing
 * HIGH to attach. */
#define USBD_DETACH_LEVEL LOW
#define USBD_PULLUP_CONTROL_FLOATING
#endif /* !defined(USBD_ATTACH_PINNAME) && !USBD_HAVE_INTERNAL_PULLUPS */

vs:

#if defined(USBD_ATTACH_PIN)
    #define USBD_PULLUP_CONTROL_PINNAME digitalPinToPinName(USBD_ATTACH_PIN)
    #define USBD_DETACH_LEVEL !(USBD_ATTACH_LEVEL)
#elif defined(USBD_DETACH_PIN)
    #define USBD_DETACH_PINNAME digitalPinToPinName(USBD_DETACH_PIN)
    #define USBD_ATTACH_LEVEL !(USBD_DETACH_LEVEL)
#elif !USBD_HAVE_INTERNAL_PULLUPS
    /* When no USB attach and detach pins were defined, and the USB module
     * also does not have any builtin pullups, assume there is a fixed
     * external pullup and apply the D+ trick. */
    #if defined(USE_USB_HS_IN_FS)
        #define USBD_PULLUP_CONTROL_PINNAME USB_OTG_HS_DP
    #elif defined(USB_OTG_FS)
        #define USBD_PULLUP_CONTROL_PINNAME USB_OTG_FS_DP
    #else /* USB */
        #define USBD_PULLUP_CONTROL_PINNAME  USB_DP
    #endif
    /* Detach by writing LOW, but leave floating instead of writing
     * HIGH to attach. */
    #define USBD_DETACH_LEVEL LOW
    #define USBD_PULLUP_CONTROL_FLOATING
#endif /* !defined(USBD_ATTACH_PINNAME) && !USBD_HAVE_INTERNAL_PULLUPS */

The latter is IMHO a lot more readable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions