Menu

#600 indentation preprocessor inside functions

open
nobody
2025-07-21
2025-07-03
Marco
No

Hi everybody,
I have issues with preprocessor indentation inside functions;

original:

void init(void)
{
#ifdef ENABLE && (ENABLE==1)
  os_queue_create(&queue, "QUEUE", QUEUE_MESSAGE_SIZE, buffer, QUEUE_MAX_FILES * QUEUE_BYTE_SIZE);
#endif // #if defined(ENABLE) && (ENABLE==1)
}

bool add_file(char* filepath)
{
#ifdef ENABLE && (ENABLE==1)
  int res;
  int len;

  len = strlen(filepath);
  if (len>QUEUE_MESSAGE_SIZE)
      return false;

    res = os_queue_send(&queue, filepath, 100);
    ASSERT(res==0);
    if (res!=0)
      return false;
    return true;
#else
    return true;
#endif
}

after astyle:

void init(void)
{
#ifdef ENABLE && (ENABLE==1)
os_queue_create(&queue, "QUEUE", QUEUE_MESSAGE_SIZE, buffer, QUEUE_MAX_FILES * QUEUE_BYTE_SIZE);
#endif // #if defined(ENABLE) && (ENABLE==1)
}

  bool add_file(char* filepath)
  {
#ifdef ENABLE && (ENABLE==1)
int res;
int len;

    len = strlen(filepath);
    if (len>QUEUE_MESSAGE_SIZE)
      return false;

    res = os_queue_send(&queue, filepath, 100);
    ASSERT(res==0);
    if (res!=0)
      return false;
    return true;
#else
return true;
#endif
}

the second function has a strange indentation, I tried with some options but it does not change.

This is my standard configuration:
AStyle version 3.6
--suffix=none
--style=allman
--indent=spaces=2
--indent-switches
--pad-comma
--lineend=windows
--preserve-date
--formatted

Thanks,
Marco

Discussion

  • André Simon

    André Simon - 2025-07-15

    Hi, is there any code before this function to trigger this?

     
  • Marco

    Marco - 2025-07-17

    Hello @saalen,
    yes, there are some rows of code:

    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    ///////////////////////////////////////////////////////////
    // INCLUDE COMUNI
    ///////////////////////////////////////////////////////////
    #include "configBase.h"
    #include "errorCode.h"//serve x AP_ERR
    #include "message.h"
    #include "myLib.h"//serve per AM
    #include "apEnum.h"
    #include "vegaassert.h"
    
    ///////////////////////////////////////////////////////////
    // INCLUDE SPECIFICI
    ///////////////////////////////////////////////////////////
    #include "os_file.h"
    #include "mainStart.h"
    #include "dbp.h"
    #include "ade_data.h"
    
    ///////////////////////////////////////////////////////////
    // INCLUDE: FINE
    ///////////////////////////////////////////////////////////
    
    #if defined(BSP_EN_MTP) && (BSP_EN_MTP==1)
    
    #define QUEUE_MTP_AUTOMATIC_ACTIONS_MAX_FILES           20
    #define QUEUE_MTP_AUTOMATIC_ACTIONS_MESSAGE_SIZE        16 //*32 bit unsigned long
    #define QUEUE_MTP_AUTOMATIC_ACTIONS_MESSAGE_BYTE_SIZE   (QUEUE_MTP_AUTOMATIC_ACTIONS_MESSAGE_SIZE * sizeof(unsigned long))
    

    I found the problem just now:

    #define QUEUE_MTP_AUTOMATIC_ACTIONS_MESSAGE_SIZE        16 //*32 bit unsigned 
    

    the comment after 16 value is with * and this brokes something with astyle, but doesn't with ide/compiler.
    Without * astyle works fine!

    Thanks anyway,
    Marco

     
    • w-peuker

      w-peuker - 2025-07-17

      Hi Marco, adding a single space after // also increases readability for humans. Therefore, many style guides prescribe this type of visual padding between the “frame” of the comment and its content.

       
  • André Simon

    André Simon - 2025-07-21

    I have pushed a fix to the repo

     

Log in to post a comment.

MongoDB Logo MongoDB