This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

difficult question

what is th eorder of presedents?

is 2 + 3 * 5 = 32 or 17

Parents
  • Per, you are now in Violation of Section 4.5.2A.
    Expect the Code-Monkey Police to have you and your code impounded. </sarcasm>

    "Never-Ever think that too many parentheses can be 'too many' within source code."

    Andy, good one.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

Reply
  • Per, you are now in Violation of Section 4.5.2A.
    Expect the Code-Monkey Police to have you and your code impounded. </sarcasm>

    "Never-Ever think that too many parentheses can be 'too many' within source code."

    Andy, good one.

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

Children
  • I once worked with a certain other well-known high-dollar commercial compiler where using too many parentheses actually caused it to generate incorrect code!

    I think a far better rule is:

    if you feel the need to add parentheses, then the expression is too complicated - break it down into separate steps

    It is highly unlikely that this will have any negative impact on the code generated by a good, modern optimising compiler...

  • Andy,

    I agree. Break it down into smaller statements!

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA

  •  * 918518FD-2C28-4BC6-AF11-83689E384065 thinks that 2 + 3 * 5 is broken down into a nice easyexpression not needing further subdivision, even if we still haven't figured out the OP:s suggested order of evaluation ;)

  • What is a presedent?

    Is Obama the last in the list?

  • Indeed.

    But, if it were more complex, and you were contemplating adding parentheses, then I'd recommend that you break it down instead.

  • I'm still trying to figure out how to get 32 out of that.

  • I searched some of my code for "32" an found many of them... along with "lots of parentheses" too!

    typedef volatile unsigned long   vu32;
    typedef          unsigned int    u16;
    
    #define GPIO_MAP_PA     ( (vu32 ) 0x40010800 ) // Cortex Mapped
    
    #define GPIOx_OFFSET_BRR  (0x14)    // Port bit reset register (GPIOx_BRR)
    
    #define PA_BRR          ( GPIO_MAP_PA + GPIOx_OFFSET_BRR  ) // resetting individual bits
    
    #define GPIO_Pin_0      ( (u16) 0x0001 )  /* Pin  0 selected */
    #define GPIO_Pin_1      ( (u16) 0x0002 )  /* Pin  1 selected */
    #define GPIO_Pin_2      ( (u16) 0x0004 )  /* Pin  2 selected */
    #define GPIO_Pin_3      ( (u16) 0x0008 )  /* Pin  3 selected */
    #define GPIO_Pin_4      ( (u16) 0x0010 )  /* Pin  4 selected */
    #define GPIO_Pin_5      ( (u16) 0x0020 )  /* Pin  5 selected */
    #define GPIO_Pin_6      ( (u16) 0x0040 )  /* Pin  6 selected */
    #define GPIO_Pin_7      ( (u16) 0x0080 )  /* Pin  7 selected */
    #define GPIO_Pin_8      ( (u16) 0x0100 )  /* Pin  8 selected */
    #define GPIO_Pin_9      ( (u16) 0x0200 )  /* Pin  9 selected */
    #define GPIO_Pin_10     ( (u16) 0x0400 )  /* Pin 10 selected */
    #define GPIO_Pin_11     ( (u16) 0x0800 )  /* Pin 11 selected */
    #define GPIO_Pin_12     ( (u16) 0x1000 )  /* Pin 12 selected */
    #define GPIO_Pin_13     ( (u16) 0x2000 )  /* Pin 13 selected */
    #define GPIO_Pin_14     ( (u16) 0x4000 )  /* Pin 14 selected */
    #define GPIO_Pin_15     ( (u16) 0x8000 )  /* Pin 15 selected */
    #define GPIO_Pin_All    ( (u16) 0xFFFF )  /* All pins selected */
    
    
    #define PA0_RESET   ( (*(vu32 *)PA_BRR) = GPIO_Pin_0  )      // RESET BIT
    #define PA1_RESET   ( (*(vu32 *)PA_BRR) = GPIO_Pin_1  )
    #define PA2_RESET   ( (*(vu32 *)PA_BRR) = GPIO_Pin_2  )
    #define PA3_RESET   ( (*(vu32 *)PA_BRR) = GPIO_Pin_3  )
    #define PA4_RESET   ( (*(vu32 *)PA_BRR) = GPIO_Pin_4  )
    #define PA5_RESET   ( (*(vu32 *)PA_BRR) = GPIO_Pin_5  )
    #define PA6_RESET   ( (*(vu32 *)PA_BRR) = GPIO_Pin_6  )
    #define PA7_RESET   ( (*(vu32 *)PA_BRR) = GPIO_Pin_7  )
    #define PA8_RESET   ( (*(vu32 *)PA_BRR) = GPIO_Pin_8  )
    #define PA9_RESET   ( (*(vu32 *)PA_BRR) = GPIO_Pin_9  )
    #define PA10_RESET  ( (*(vu32 *)PA_BRR) = GPIO_Pin_10 )
    #define PA11_RESET  ( (*(vu32 *)PA_BRR) = GPIO_Pin_11 )
    #define PA12_RESET  ( (*(vu32 *)PA_BRR) = GPIO_Pin_12 )
    #define PA13_RESET  ( (*(vu32 *)PA_BRR) = GPIO_Pin_13 )
    #define PA14_RESET  ( (*(vu32 *)PA_BRR) = GPIO_Pin_14 )
    #define PA15_RESET  ( (*(vu32 *)PA_BRR) = GPIO_Pin_15 )
    

    --Cpt. Vince Foster
    2nd Cannon Place
    Fort Marcy Park, VA