#define issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • axr0284

    #1

    #define issue

    Hi,
    I am currently looking at some code and I am having difficulties
    figuring out what this peace does:
    Code:
    #define FLT_INIT(iEnumValue,boolActive,iWord,iBitMask,iTDS,strDesc)
    iEnumValue,
    typedef enum { FAULT_TABLE_MACRO NUMBER_OF_FAULTS } enumFaults;
    #undef  FLT_INIT
    
    //Format:       (iEnumValue,					boolActive,	iWord,	iBitMask,	iTDS,
    strDesc)
    #define FAULT_TABLE_MACRO \
    FLT_INIT(FAULT_PWRMOD_BULK_LOW_0,			FALSE,		0,	0x00000001,	0,	"Mod 0
    Bulk V L")\
    FLT_INIT(FAULT_PWRMOD_BULK_HIGH_0,			FALSE,		0,	0x00000002,	0,	"Mod 0
    Bulk V H")\
    ..
    ..
    ..
    ..
    Can anybody shed some light on this even if it is in a general sense.
    I understand that enumFaults can have two values FAULT_TABLE_MAC RO and
    NUMBER_OF_FAULT S but why is the #define #undef there.
    I also do not see NUMBER_OF_FAULT S anywhere else in the code which is
    strange. I know it's hard to help without the complete file but any
    idea would help here. Thanks,
    Amish

  • Barry Schwarz

    #2
    Re: #define issue

    On Oct 24, 10:41 am, axr0284 <axr0...@yahoo. comwrote:
    Hi,
    I am currently looking at some code and I am having difficulties
    figuring out what this peace does:
    Code:
    The line wrap on your message makes it very hard to tell which are
    true new lines and which are Usenet artifacts.
    [QUOTE]
    #define FLT_INIT(iEnumValue,boolActive,iWord,iBitMask,iTDS,strDesc)
    iEnumValue,[/QUOTE]
    
    If this is truly the end of a line, then FLT_INIT is a macro that
    takes six arguments and produces a token that consists of the first
    argument followed by a comma.
    
    If not, the next line makes no sense.
    [QUOTE]
            typedef enum { FAULT_TABLE_MACRO NUMBER_OF_FAULTS } enumFaults;[/QUOTE]
    
    This declares a type (enumFaults) and two integer constants (the first
    is an alias for 0 and the second an alias for 1).
    [QUOTE]
    #undef  FLT_INIT[/QUOTE]
    
    Whatever the intent of FLT_INIT was, it won't do it anymore.
    [QUOTE]
    >
    //Format:       (iEnumValue,                                    boolActive,     iWord,  iBitMask,       iTDS,
    strDesc)[/QUOTE]
    
    This looks like a very long single comment line.
    [QUOTE]
    #define FAULT_TABLE_MACRO \
            FLT_INIT(FAULT_PWRMOD_BULK_LOW_0,[/QUOTE]
    
    Since FLT_INIT is no longer defined, this should lead to a syntax
    error if FAULT_TABLE_MACRO is ever used in the code.
    [QUOTE]
    >FALSE,          0,      0x00000001,     0,      "Mod 0
    Bulk V L")\
            FLT_INIT(FAULT_PWRMOD_BULK_HIGH_0,                      FALSE,          0,      0x00000002,     0,      "Mod 0
    Bulk V H")\
    .
    .
    .
    .
    >
    [/QUOTE]
    >
    Can anybody shed some light on this even if it is in a general sense.
    I understand that enumFaults can have two values FAULT_TABLE_MAC RO and
    NUMBER_OF_FAULT S but why is the #define #undef there.
    I also do not see NUMBER_OF_FAULT S anywhere else in the code which is
    strange. I know it's hard to help without the complete file but any
    idea would help here. Thanks,
    Amish

    Comment

    • Thad Smith

      #3
      Re: #define issue

      axr0284 wrote:
      Hi,
      I am currently looking at some code and I am having difficulties
      figuring out what this peace does:
      Code:
      #define FLT_INIT(iEnumValue,boolActive,iWord,iBitMask,iTDS,strDesc)
      iEnumValue,
      	typedef enum { FAULT_TABLE_MACRO NUMBER_OF_FAULTS } enumFaults;
      #undef  FLT_INIT
      >
      //Format:       (iEnumValue,					boolActive,	iWord,	iBitMask,	iTDS,
      strDesc)
      #define FAULT_TABLE_MACRO \
      	FLT_INIT(FAULT_PWRMOD_BULK_LOW_0,			FALSE,		0,	0x00000001,	0,	"Mod 0
      Bulk V L")\
      	FLT_INIT(FAULT_PWRMOD_BULK_HIGH_0,			FALSE,		0,	0x00000002,	0,	"Mod 0
      Bulk V H")\
      .
      .
      .
      .
      >
      >
      It looks like you attempted to retype the code. It is much better to
      cut and paste code, instead, since you won't make copy errors (such as a
      missing comma in the enum declaration). Further, I think significant
      context is missing.

      That said, I suspect that FLT_INIT is a macro that has multiple
      definitions so that a single table, with multiple items, is placed
      inside multiple constructs, such as enum constant declaration and
      structure or array initialization. The advantage to this technique is
      that all the items describing some item are kept together and the
      initialization values don't need to be repeated.

      --
      Thad

      Comment

      • CBFalconer

        #4
        Re: #define issue

        Barry Schwarz wrote:
        axr0284 <axr0...@yahoo. comwrote:
        >
        >I am currently looking at some code and I am having difficulties
        >figuring out what this peace does:
        >[CODE]
        >
        The line wrap on your message makes it very hard to tell which are
        true new lines and which are Usenet artifacts.
        In other words don't use tabs, and ensure your lines do not exceed
        72 chars wide. Holding them under 67 is even better.

        --
        Chuck F (cbfalconer at maineline dot net)
        Available for consulting/temporary embedded and systems.
        <http://cbfalconer.home .att.net>



        --
        Posted via a free Usenet account from http://www.teranews.co m

        Comment

        • Andrew Thompson

          #5
          Re: #define issue

          On Oct 25, 10:52 am, Barry Schwarz <schwar...@yaho o.comwrote:
          ....
          The line wrap on your message makes it very hard to tell which are
          true new lines and which are Usenet artifacts.
          This small Java based tool might help with that.
          <http://www.physci.org/twc.jnlp>

          --
          Andrew Thompson

          Comment

          Working...