Thread: Explanation on order of precedence?

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    91

    Explanation on order of precedence?

    I am under the impression that the -> takes precedence over '.' Is this true? The first statement below works but looks to me like there should be parenthesis.

    Can someone tell me what each of these means?

    Code:
    &huart2.Instance->TDR
    (&huart2.Instance)->TDR
    &(huart2.Instance)->TDR
    &(huart2.Instance->TDR)
    Thanks
    Last edited by ridgerunnersjw; 03-19-2021 at 11:40 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    To check precedence, just search for a draft of the C standard, and look at the section on expressions. You'll find that these two operators have the same precedence, and the grammar indicates left-to-right grouping.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Order of Precedence question
    By Jony in forum C Programming
    Replies: 10
    Last Post: 08-22-2011, 10:55 PM
  2. Have a window take z-order precedence over - Games?
    By guitarist809 in forum Windows Programming
    Replies: 2
    Last Post: 07-19-2008, 08:11 PM
  3. order of precedence
    By the bassinvader in forum C Programming
    Replies: 6
    Last Post: 12-15-2006, 05:11 PM
  4. Replies: 15
    Last Post: 11-04-2006, 04:06 AM
  5. uncertainty in order of execution - any explanation?
    By ylzhang in forum C Programming
    Replies: 6
    Last Post: 05-31-2003, 08:04 AM

Tags for this Thread