*p++->str : Understanding evaluation of ->Postfix/Prefix operator precedence and associativityImprove INSERT-per-second performance of SQLite?Operator Precedence vs Order of EvaluationOperand evaluation order and associativityIs the behavior of i = post_increment_i() specified, unspecified, or undefined?Is a parenthesis in an expression evaluated before anything else?Who defines C operator precedence and associativity?Operator associativity and order of evaluationShort circuit evaluation of a statement with ++ operator in CCan parentheses override an expression's order of evaluation?How to justify C postfix increment operator with precedence table?

Did the Shuttle payload bay have illumination?

What's the difference between the Find Steed and Find Greater Steed spells?

Why is my 401k manager recommending me to save more?

To “Er” Is Human

Installed software from source, how to say yum not to install it from package?

Why can't i use !(single pattern) in zsh even after i turn on kshglob?

Other homotopy invariants?

Is it advisable to inform the CEO about his brother accessing his office?

Advantages of using bra-ket notation

GFCI versus circuit breaker

Lenovo Legion PXI-E61 Media Test Failure, Check Cable. Exiting PXE ROM. Then restarts and works fine

Tricky riddle from sister

Is there a word for the act of simultaneously pulling and twisting an object?

A world with roman numeral alphabet

What's the idiomatic (or best) way to trim surrounding whitespace from a string?

How useful would a hydroelectric power plant be in the post-apocalypse world?

Avoiding repetition when using the "snprintf idiom" to write text

Enterprise Layers and Naming Conventions

What could a Medieval society do with excess animal blood?

Square wave to sawtooth wave using two BJT

What was the ASCII end of medium (EM) character intended to be used for?

What is the point of using the kunai?

Can combing bent evaporator coil fins damage it?

Using quotation marks and exclamation marks



*p++->str : Understanding evaluation of ->


Postfix/Prefix operator precedence and associativityImprove INSERT-per-second performance of SQLite?Operator Precedence vs Order of EvaluationOperand evaluation order and associativityIs the behavior of i = post_increment_i() specified, unspecified, or undefined?Is a parenthesis in an expression evaluated before anything else?Who defines C operator precedence and associativity?Operator associativity and order of evaluationShort circuit evaluation of a statement with ++ operator in CCan parentheses override an expression's order of evaluation?How to justify C postfix increment operator with precedence table?













6















My question is about the following line of code, taken from "The C Programming Language" 2nd Edition:



*p++->str;


The book says that this line of code increments p after accessing whatever str points to.



My understanding is as follows:




  • Precedence and associativity say that the order in which the operators will be evaluated is



    1. ->

    2. ++

    3. *


  • The postfix increment operator ++ yields a value (i.e. value of its operand), and has the side effect of incrementing this operand before the next sequence point (i.e. the following ;)


  • Precedence and associativity describe the order in which operators are evaluated and not the order in which the operands of the operators are evaluated.


My Question:



My question is around the evaluation of the highest precedence operator (->) in this expression. I believe that to evaluate this operator means to evaluate both of the operands, and then apply the operator.



From the perspective of the -> operator, is the left operand p or p++? I understand that both return the same value.



However, if the first option is correct, I would ask "how is it possible for the evaluation of the -> operator to ignore the presence of the ++".



If the second option is correct, I would ask "doesn't the evaluation of -> in this case then require the evaluation of a lower precedence operator ++ here (and the evaluation of ++ completes before that of ->)"?










share|improve this question







New contributor



thatmarkdude is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • 3





    The operand to -> is p++, and the reason their relative precedence doesn’t matter is that ++ is a unary operator. (But order of evaluation doesn’t follow precedence anyway.)

    – Ry-
    8 hours ago






  • 2





    The ++ increment occurs before the next 'sequence point'. There isn't a sequence point within the expression *p++->string, so the increment occurs before the next sequence point in the larger context in which the expression appears.

    – Jonathan Leffler
    8 hours ago











  • Put simply, ++ isn't an expression, it's an operator acting on p, so the operand has to be p++ and not p.

    – teppic
    7 hours ago






  • 3





    *p++->str; is clearly bad code. It's hard enough to understand that it generated a seven-plus paragraph question, didn't it?

    – Andrew Henle
    7 hours ago
















6















My question is about the following line of code, taken from "The C Programming Language" 2nd Edition:



*p++->str;


The book says that this line of code increments p after accessing whatever str points to.



My understanding is as follows:




  • Precedence and associativity say that the order in which the operators will be evaluated is



    1. ->

    2. ++

    3. *


  • The postfix increment operator ++ yields a value (i.e. value of its operand), and has the side effect of incrementing this operand before the next sequence point (i.e. the following ;)


  • Precedence and associativity describe the order in which operators are evaluated and not the order in which the operands of the operators are evaluated.


My Question:



My question is around the evaluation of the highest precedence operator (->) in this expression. I believe that to evaluate this operator means to evaluate both of the operands, and then apply the operator.



From the perspective of the -> operator, is the left operand p or p++? I understand that both return the same value.



However, if the first option is correct, I would ask "how is it possible for the evaluation of the -> operator to ignore the presence of the ++".



If the second option is correct, I would ask "doesn't the evaluation of -> in this case then require the evaluation of a lower precedence operator ++ here (and the evaluation of ++ completes before that of ->)"?










share|improve this question







New contributor



thatmarkdude is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.














  • 3





    The operand to -> is p++, and the reason their relative precedence doesn’t matter is that ++ is a unary operator. (But order of evaluation doesn’t follow precedence anyway.)

    – Ry-
    8 hours ago






  • 2





    The ++ increment occurs before the next 'sequence point'. There isn't a sequence point within the expression *p++->string, so the increment occurs before the next sequence point in the larger context in which the expression appears.

    – Jonathan Leffler
    8 hours ago











  • Put simply, ++ isn't an expression, it's an operator acting on p, so the operand has to be p++ and not p.

    – teppic
    7 hours ago






  • 3





    *p++->str; is clearly bad code. It's hard enough to understand that it generated a seven-plus paragraph question, didn't it?

    – Andrew Henle
    7 hours ago














6












6








6








My question is about the following line of code, taken from "The C Programming Language" 2nd Edition:



*p++->str;


The book says that this line of code increments p after accessing whatever str points to.



My understanding is as follows:




  • Precedence and associativity say that the order in which the operators will be evaluated is



    1. ->

    2. ++

    3. *


  • The postfix increment operator ++ yields a value (i.e. value of its operand), and has the side effect of incrementing this operand before the next sequence point (i.e. the following ;)


  • Precedence and associativity describe the order in which operators are evaluated and not the order in which the operands of the operators are evaluated.


My Question:



My question is around the evaluation of the highest precedence operator (->) in this expression. I believe that to evaluate this operator means to evaluate both of the operands, and then apply the operator.



From the perspective of the -> operator, is the left operand p or p++? I understand that both return the same value.



However, if the first option is correct, I would ask "how is it possible for the evaluation of the -> operator to ignore the presence of the ++".



If the second option is correct, I would ask "doesn't the evaluation of -> in this case then require the evaluation of a lower precedence operator ++ here (and the evaluation of ++ completes before that of ->)"?










share|improve this question







New contributor



thatmarkdude is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











My question is about the following line of code, taken from "The C Programming Language" 2nd Edition:



*p++->str;


The book says that this line of code increments p after accessing whatever str points to.



My understanding is as follows:




  • Precedence and associativity say that the order in which the operators will be evaluated is



    1. ->

    2. ++

    3. *


  • The postfix increment operator ++ yields a value (i.e. value of its operand), and has the side effect of incrementing this operand before the next sequence point (i.e. the following ;)


  • Precedence and associativity describe the order in which operators are evaluated and not the order in which the operands of the operators are evaluated.


My Question:



My question is around the evaluation of the highest precedence operator (->) in this expression. I believe that to evaluate this operator means to evaluate both of the operands, and then apply the operator.



From the perspective of the -> operator, is the left operand p or p++? I understand that both return the same value.



However, if the first option is correct, I would ask "how is it possible for the evaluation of the -> operator to ignore the presence of the ++".



If the second option is correct, I would ask "doesn't the evaluation of -> in this case then require the evaluation of a lower precedence operator ++ here (and the evaluation of ++ completes before that of ->)"?







c operator-precedence side-effects associativity






share|improve this question







New contributor



thatmarkdude is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question







New contributor



thatmarkdude is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question






New contributor



thatmarkdude is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 8 hours ago









thatmarkdudethatmarkdude

363 bronze badges




363 bronze badges




New contributor



thatmarkdude is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




thatmarkdude is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









  • 3





    The operand to -> is p++, and the reason their relative precedence doesn’t matter is that ++ is a unary operator. (But order of evaluation doesn’t follow precedence anyway.)

    – Ry-
    8 hours ago






  • 2





    The ++ increment occurs before the next 'sequence point'. There isn't a sequence point within the expression *p++->string, so the increment occurs before the next sequence point in the larger context in which the expression appears.

    – Jonathan Leffler
    8 hours ago











  • Put simply, ++ isn't an expression, it's an operator acting on p, so the operand has to be p++ and not p.

    – teppic
    7 hours ago






  • 3





    *p++->str; is clearly bad code. It's hard enough to understand that it generated a seven-plus paragraph question, didn't it?

    – Andrew Henle
    7 hours ago













  • 3





    The operand to -> is p++, and the reason their relative precedence doesn’t matter is that ++ is a unary operator. (But order of evaluation doesn’t follow precedence anyway.)

    – Ry-
    8 hours ago






  • 2





    The ++ increment occurs before the next 'sequence point'. There isn't a sequence point within the expression *p++->string, so the increment occurs before the next sequence point in the larger context in which the expression appears.

    – Jonathan Leffler
    8 hours ago











  • Put simply, ++ isn't an expression, it's an operator acting on p, so the operand has to be p++ and not p.

    – teppic
    7 hours ago






  • 3





    *p++->str; is clearly bad code. It's hard enough to understand that it generated a seven-plus paragraph question, didn't it?

    – Andrew Henle
    7 hours ago








3




3





The operand to -> is p++, and the reason their relative precedence doesn’t matter is that ++ is a unary operator. (But order of evaluation doesn’t follow precedence anyway.)

– Ry-
8 hours ago





The operand to -> is p++, and the reason their relative precedence doesn’t matter is that ++ is a unary operator. (But order of evaluation doesn’t follow precedence anyway.)

– Ry-
8 hours ago




2




2





The ++ increment occurs before the next 'sequence point'. There isn't a sequence point within the expression *p++->string, so the increment occurs before the next sequence point in the larger context in which the expression appears.

– Jonathan Leffler
8 hours ago





The ++ increment occurs before the next 'sequence point'. There isn't a sequence point within the expression *p++->string, so the increment occurs before the next sequence point in the larger context in which the expression appears.

– Jonathan Leffler
8 hours ago













Put simply, ++ isn't an expression, it's an operator acting on p, so the operand has to be p++ and not p.

– teppic
7 hours ago





Put simply, ++ isn't an expression, it's an operator acting on p, so the operand has to be p++ and not p.

– teppic
7 hours ago




3




3





*p++->str; is clearly bad code. It's hard enough to understand that it generated a seven-plus paragraph question, didn't it?

– Andrew Henle
7 hours ago






*p++->str; is clearly bad code. It's hard enough to understand that it generated a seven-plus paragraph question, didn't it?

– Andrew Henle
7 hours ago











2 Answers
2






active

oldest

votes


















5














To understand the expression *p++->str you need to understand how *p++ works, or in general how postfix increment works on pointers.



In case of *p++, the value at the location p points to is dereferenced before the increment of the pointer p.

n1570 - §6.5.2.4/2:




The result of the postfix ++ operator is the value of the operand. As a side effect, the value of the operand object is incremented (that is, the value 1 of the appropriate type is added to it). [...]. The value computation of the result is sequenced before the side effect of updating the stored value of the operand.




In case of *p++->str, ++ and -> have equal precedence and higher than * operator. This expression will be parenthesised as *((p++)->str) as per the operator precedence and associativity rule.



One important note here is precedence and associativity has nothing to do with the order of evaluation. So, though ++ has higher precedence it is not guaranteed that p++ will be evaluated first. Which means the expression p++ (in the expression *p++->str) will be evaluated as per the rule quoted above from the standard. (p++)->str will access the str member p points to and then it's value is dereferenced and then the value of p is incremented any time between the last and next sequence point.






share|improve this answer

























  • Interesting. My book states the highest tier of precedence as () [] -> . (left to right), and the next tier as ! - ++ -- + - * & (type) sizeof (right to left). Therefore, I thought that -> operator had highest precedence here. However, I can see that this page agrees with your analysis

    – thatmarkdude
    7 hours ago











  • @thatmarkdude; I edited my answer. Please read it once more.

    – haccks
    7 hours ago






  • 2





    @thatmarkdude The ++ and -- in the second tier are prefix operators. Your book is missing the postfix ++ and -- in the first tier.

    – interjay
    7 hours ago






  • 1





    @thatmarkdude for reference here's a full list i.imgur.com/hbeIOSY.png

    – teppic
    7 hours ago






  • 1





    Re: “So, though ++ has higher precedence it is not guaranteed that p++ will be evaluated first”: It is guaranteed the value computation of ++ occurs before ->. Per C 2018 6.5 1, “The value computations of the operands of an operator are sequenced before the value computation of the result of the operator.” The side effect is not sequenced by this, but the value computation is.

    – Eric Postpischil
    6 hours ago


















6














Postfix ++ and -> have the same precedence. a++->b parses as (a++)->b, i.e. ++ is done first.



*p++->str; executes as follows:



  • The expression parses as *((p++)->str). -> is a meta-postfix operator, i.e. ->foo is a postfix operator for all identifiers foo. Postfix operators have the highest precedence, followed by prefix operators (such as *). Associativity doesn't really apply: There is only one operand and only one way to "associate" it with a given operator.


  • p++ is evaluated. This yields the (old) value of p and schedules an update, setting p to p+1, which will happen at some point before the next sequence point. Call the result of this expression tmp0.


  • tmp0->str is evaluated. This is equivalent to (*tmp0).str: It dereferences tmp0, which must be a pointer to a struct or union, and gets the str member. Call the result of this expression tmp1.


  • *tmp1 is evaluated. This dereferences tmp1, which must be a pointer (to a complete type). Call the result of this expression tmp2.


  • tmp2 is ignored (the expression is in void context). We reach ; and p must have been incremented before this point.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    thatmarkdude is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56826111%2fp-str-understanding-evaluation-of%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    To understand the expression *p++->str you need to understand how *p++ works, or in general how postfix increment works on pointers.



    In case of *p++, the value at the location p points to is dereferenced before the increment of the pointer p.

    n1570 - §6.5.2.4/2:




    The result of the postfix ++ operator is the value of the operand. As a side effect, the value of the operand object is incremented (that is, the value 1 of the appropriate type is added to it). [...]. The value computation of the result is sequenced before the side effect of updating the stored value of the operand.




    In case of *p++->str, ++ and -> have equal precedence and higher than * operator. This expression will be parenthesised as *((p++)->str) as per the operator precedence and associativity rule.



    One important note here is precedence and associativity has nothing to do with the order of evaluation. So, though ++ has higher precedence it is not guaranteed that p++ will be evaluated first. Which means the expression p++ (in the expression *p++->str) will be evaluated as per the rule quoted above from the standard. (p++)->str will access the str member p points to and then it's value is dereferenced and then the value of p is incremented any time between the last and next sequence point.






    share|improve this answer

























    • Interesting. My book states the highest tier of precedence as () [] -> . (left to right), and the next tier as ! - ++ -- + - * & (type) sizeof (right to left). Therefore, I thought that -> operator had highest precedence here. However, I can see that this page agrees with your analysis

      – thatmarkdude
      7 hours ago











    • @thatmarkdude; I edited my answer. Please read it once more.

      – haccks
      7 hours ago






    • 2





      @thatmarkdude The ++ and -- in the second tier are prefix operators. Your book is missing the postfix ++ and -- in the first tier.

      – interjay
      7 hours ago






    • 1





      @thatmarkdude for reference here's a full list i.imgur.com/hbeIOSY.png

      – teppic
      7 hours ago






    • 1





      Re: “So, though ++ has higher precedence it is not guaranteed that p++ will be evaluated first”: It is guaranteed the value computation of ++ occurs before ->. Per C 2018 6.5 1, “The value computations of the operands of an operator are sequenced before the value computation of the result of the operator.” The side effect is not sequenced by this, but the value computation is.

      – Eric Postpischil
      6 hours ago















    5














    To understand the expression *p++->str you need to understand how *p++ works, or in general how postfix increment works on pointers.



    In case of *p++, the value at the location p points to is dereferenced before the increment of the pointer p.

    n1570 - §6.5.2.4/2:




    The result of the postfix ++ operator is the value of the operand. As a side effect, the value of the operand object is incremented (that is, the value 1 of the appropriate type is added to it). [...]. The value computation of the result is sequenced before the side effect of updating the stored value of the operand.




    In case of *p++->str, ++ and -> have equal precedence and higher than * operator. This expression will be parenthesised as *((p++)->str) as per the operator precedence and associativity rule.



    One important note here is precedence and associativity has nothing to do with the order of evaluation. So, though ++ has higher precedence it is not guaranteed that p++ will be evaluated first. Which means the expression p++ (in the expression *p++->str) will be evaluated as per the rule quoted above from the standard. (p++)->str will access the str member p points to and then it's value is dereferenced and then the value of p is incremented any time between the last and next sequence point.






    share|improve this answer

























    • Interesting. My book states the highest tier of precedence as () [] -> . (left to right), and the next tier as ! - ++ -- + - * & (type) sizeof (right to left). Therefore, I thought that -> operator had highest precedence here. However, I can see that this page agrees with your analysis

      – thatmarkdude
      7 hours ago











    • @thatmarkdude; I edited my answer. Please read it once more.

      – haccks
      7 hours ago






    • 2





      @thatmarkdude The ++ and -- in the second tier are prefix operators. Your book is missing the postfix ++ and -- in the first tier.

      – interjay
      7 hours ago






    • 1





      @thatmarkdude for reference here's a full list i.imgur.com/hbeIOSY.png

      – teppic
      7 hours ago






    • 1





      Re: “So, though ++ has higher precedence it is not guaranteed that p++ will be evaluated first”: It is guaranteed the value computation of ++ occurs before ->. Per C 2018 6.5 1, “The value computations of the operands of an operator are sequenced before the value computation of the result of the operator.” The side effect is not sequenced by this, but the value computation is.

      – Eric Postpischil
      6 hours ago













    5












    5








    5







    To understand the expression *p++->str you need to understand how *p++ works, or in general how postfix increment works on pointers.



    In case of *p++, the value at the location p points to is dereferenced before the increment of the pointer p.

    n1570 - §6.5.2.4/2:




    The result of the postfix ++ operator is the value of the operand. As a side effect, the value of the operand object is incremented (that is, the value 1 of the appropriate type is added to it). [...]. The value computation of the result is sequenced before the side effect of updating the stored value of the operand.




    In case of *p++->str, ++ and -> have equal precedence and higher than * operator. This expression will be parenthesised as *((p++)->str) as per the operator precedence and associativity rule.



    One important note here is precedence and associativity has nothing to do with the order of evaluation. So, though ++ has higher precedence it is not guaranteed that p++ will be evaluated first. Which means the expression p++ (in the expression *p++->str) will be evaluated as per the rule quoted above from the standard. (p++)->str will access the str member p points to and then it's value is dereferenced and then the value of p is incremented any time between the last and next sequence point.






    share|improve this answer















    To understand the expression *p++->str you need to understand how *p++ works, or in general how postfix increment works on pointers.



    In case of *p++, the value at the location p points to is dereferenced before the increment of the pointer p.

    n1570 - §6.5.2.4/2:




    The result of the postfix ++ operator is the value of the operand. As a side effect, the value of the operand object is incremented (that is, the value 1 of the appropriate type is added to it). [...]. The value computation of the result is sequenced before the side effect of updating the stored value of the operand.




    In case of *p++->str, ++ and -> have equal precedence and higher than * operator. This expression will be parenthesised as *((p++)->str) as per the operator precedence and associativity rule.



    One important note here is precedence and associativity has nothing to do with the order of evaluation. So, though ++ has higher precedence it is not guaranteed that p++ will be evaluated first. Which means the expression p++ (in the expression *p++->str) will be evaluated as per the rule quoted above from the standard. (p++)->str will access the str member p points to and then it's value is dereferenced and then the value of p is incremented any time between the last and next sequence point.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 5 hours ago









    Jonathan Leffler

    584k96 gold badges705 silver badges1055 bronze badges




    584k96 gold badges705 silver badges1055 bronze badges










    answered 7 hours ago









    hacckshaccks

    87.4k21 gold badges135 silver badges223 bronze badges




    87.4k21 gold badges135 silver badges223 bronze badges












    • Interesting. My book states the highest tier of precedence as () [] -> . (left to right), and the next tier as ! - ++ -- + - * & (type) sizeof (right to left). Therefore, I thought that -> operator had highest precedence here. However, I can see that this page agrees with your analysis

      – thatmarkdude
      7 hours ago











    • @thatmarkdude; I edited my answer. Please read it once more.

      – haccks
      7 hours ago






    • 2





      @thatmarkdude The ++ and -- in the second tier are prefix operators. Your book is missing the postfix ++ and -- in the first tier.

      – interjay
      7 hours ago






    • 1





      @thatmarkdude for reference here's a full list i.imgur.com/hbeIOSY.png

      – teppic
      7 hours ago






    • 1





      Re: “So, though ++ has higher precedence it is not guaranteed that p++ will be evaluated first”: It is guaranteed the value computation of ++ occurs before ->. Per C 2018 6.5 1, “The value computations of the operands of an operator are sequenced before the value computation of the result of the operator.” The side effect is not sequenced by this, but the value computation is.

      – Eric Postpischil
      6 hours ago

















    • Interesting. My book states the highest tier of precedence as () [] -> . (left to right), and the next tier as ! - ++ -- + - * & (type) sizeof (right to left). Therefore, I thought that -> operator had highest precedence here. However, I can see that this page agrees with your analysis

      – thatmarkdude
      7 hours ago











    • @thatmarkdude; I edited my answer. Please read it once more.

      – haccks
      7 hours ago






    • 2





      @thatmarkdude The ++ and -- in the second tier are prefix operators. Your book is missing the postfix ++ and -- in the first tier.

      – interjay
      7 hours ago






    • 1





      @thatmarkdude for reference here's a full list i.imgur.com/hbeIOSY.png

      – teppic
      7 hours ago






    • 1





      Re: “So, though ++ has higher precedence it is not guaranteed that p++ will be evaluated first”: It is guaranteed the value computation of ++ occurs before ->. Per C 2018 6.5 1, “The value computations of the operands of an operator are sequenced before the value computation of the result of the operator.” The side effect is not sequenced by this, but the value computation is.

      – Eric Postpischil
      6 hours ago
















    Interesting. My book states the highest tier of precedence as () [] -> . (left to right), and the next tier as ! - ++ -- + - * & (type) sizeof (right to left). Therefore, I thought that -> operator had highest precedence here. However, I can see that this page agrees with your analysis

    – thatmarkdude
    7 hours ago





    Interesting. My book states the highest tier of precedence as () [] -> . (left to right), and the next tier as ! - ++ -- + - * & (type) sizeof (right to left). Therefore, I thought that -> operator had highest precedence here. However, I can see that this page agrees with your analysis

    – thatmarkdude
    7 hours ago













    @thatmarkdude; I edited my answer. Please read it once more.

    – haccks
    7 hours ago





    @thatmarkdude; I edited my answer. Please read it once more.

    – haccks
    7 hours ago




    2




    2





    @thatmarkdude The ++ and -- in the second tier are prefix operators. Your book is missing the postfix ++ and -- in the first tier.

    – interjay
    7 hours ago





    @thatmarkdude The ++ and -- in the second tier are prefix operators. Your book is missing the postfix ++ and -- in the first tier.

    – interjay
    7 hours ago




    1




    1





    @thatmarkdude for reference here's a full list i.imgur.com/hbeIOSY.png

    – teppic
    7 hours ago





    @thatmarkdude for reference here's a full list i.imgur.com/hbeIOSY.png

    – teppic
    7 hours ago




    1




    1





    Re: “So, though ++ has higher precedence it is not guaranteed that p++ will be evaluated first”: It is guaranteed the value computation of ++ occurs before ->. Per C 2018 6.5 1, “The value computations of the operands of an operator are sequenced before the value computation of the result of the operator.” The side effect is not sequenced by this, but the value computation is.

    – Eric Postpischil
    6 hours ago





    Re: “So, though ++ has higher precedence it is not guaranteed that p++ will be evaluated first”: It is guaranteed the value computation of ++ occurs before ->. Per C 2018 6.5 1, “The value computations of the operands of an operator are sequenced before the value computation of the result of the operator.” The side effect is not sequenced by this, but the value computation is.

    – Eric Postpischil
    6 hours ago











    6














    Postfix ++ and -> have the same precedence. a++->b parses as (a++)->b, i.e. ++ is done first.



    *p++->str; executes as follows:



    • The expression parses as *((p++)->str). -> is a meta-postfix operator, i.e. ->foo is a postfix operator for all identifiers foo. Postfix operators have the highest precedence, followed by prefix operators (such as *). Associativity doesn't really apply: There is only one operand and only one way to "associate" it with a given operator.


    • p++ is evaluated. This yields the (old) value of p and schedules an update, setting p to p+1, which will happen at some point before the next sequence point. Call the result of this expression tmp0.


    • tmp0->str is evaluated. This is equivalent to (*tmp0).str: It dereferences tmp0, which must be a pointer to a struct or union, and gets the str member. Call the result of this expression tmp1.


    • *tmp1 is evaluated. This dereferences tmp1, which must be a pointer (to a complete type). Call the result of this expression tmp2.


    • tmp2 is ignored (the expression is in void context). We reach ; and p must have been incremented before this point.






    share|improve this answer



























      6














      Postfix ++ and -> have the same precedence. a++->b parses as (a++)->b, i.e. ++ is done first.



      *p++->str; executes as follows:



      • The expression parses as *((p++)->str). -> is a meta-postfix operator, i.e. ->foo is a postfix operator for all identifiers foo. Postfix operators have the highest precedence, followed by prefix operators (such as *). Associativity doesn't really apply: There is only one operand and only one way to "associate" it with a given operator.


      • p++ is evaluated. This yields the (old) value of p and schedules an update, setting p to p+1, which will happen at some point before the next sequence point. Call the result of this expression tmp0.


      • tmp0->str is evaluated. This is equivalent to (*tmp0).str: It dereferences tmp0, which must be a pointer to a struct or union, and gets the str member. Call the result of this expression tmp1.


      • *tmp1 is evaluated. This dereferences tmp1, which must be a pointer (to a complete type). Call the result of this expression tmp2.


      • tmp2 is ignored (the expression is in void context). We reach ; and p must have been incremented before this point.






      share|improve this answer

























        6












        6








        6







        Postfix ++ and -> have the same precedence. a++->b parses as (a++)->b, i.e. ++ is done first.



        *p++->str; executes as follows:



        • The expression parses as *((p++)->str). -> is a meta-postfix operator, i.e. ->foo is a postfix operator for all identifiers foo. Postfix operators have the highest precedence, followed by prefix operators (such as *). Associativity doesn't really apply: There is only one operand and only one way to "associate" it with a given operator.


        • p++ is evaluated. This yields the (old) value of p and schedules an update, setting p to p+1, which will happen at some point before the next sequence point. Call the result of this expression tmp0.


        • tmp0->str is evaluated. This is equivalent to (*tmp0).str: It dereferences tmp0, which must be a pointer to a struct or union, and gets the str member. Call the result of this expression tmp1.


        • *tmp1 is evaluated. This dereferences tmp1, which must be a pointer (to a complete type). Call the result of this expression tmp2.


        • tmp2 is ignored (the expression is in void context). We reach ; and p must have been incremented before this point.






        share|improve this answer













        Postfix ++ and -> have the same precedence. a++->b parses as (a++)->b, i.e. ++ is done first.



        *p++->str; executes as follows:



        • The expression parses as *((p++)->str). -> is a meta-postfix operator, i.e. ->foo is a postfix operator for all identifiers foo. Postfix operators have the highest precedence, followed by prefix operators (such as *). Associativity doesn't really apply: There is only one operand and only one way to "associate" it with a given operator.


        • p++ is evaluated. This yields the (old) value of p and schedules an update, setting p to p+1, which will happen at some point before the next sequence point. Call the result of this expression tmp0.


        • tmp0->str is evaluated. This is equivalent to (*tmp0).str: It dereferences tmp0, which must be a pointer to a struct or union, and gets the str member. Call the result of this expression tmp1.


        • *tmp1 is evaluated. This dereferences tmp1, which must be a pointer (to a complete type). Call the result of this expression tmp2.


        • tmp2 is ignored (the expression is in void context). We reach ; and p must have been incremented before this point.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 7 hours ago









        melpomenemelpomene

        69.6k5 gold badges55 silver badges98 bronze badges




        69.6k5 gold badges55 silver badges98 bronze badges




















            thatmarkdude is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            thatmarkdude is a new contributor. Be nice, and check out our Code of Conduct.












            thatmarkdude is a new contributor. Be nice, and check out our Code of Conduct.











            thatmarkdude is a new contributor. Be nice, and check out our Code of Conduct.














            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56826111%2fp-str-understanding-evaluation-of%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            The fall designs the understood secretary. Looking glass Science Shock Discovery Hot Everybody Loves Raymond Smile 곳 서비스 성실하다 Defas Kaloolon Definition: To combine or impregnate with sulphur or any of its compounds as to sulphurize caoutchouc in vulcanizing Flame colored Reason Useful Thin Help 갖다 유명하다 낙엽 장례식 Country Iron Definition: A fencer a gladiator one who exhibits his skill in the use of the sword Definition: The American black throated bunting Spiza Americana Nostalgic Needy Method to my madness 시키다 평가되다 전부 소설가 우아하다 Argument Tin Feeling Representative Gym Music Gaur Chicken 일쑤 코치 편 학생증 The harbor values the sugar. Vasagle Yammoe Enstatite Definition: Capable of being limited Road Neighborly Five Refer Built Kangaroo 비비다 Degree Release Bargain Horse 하루 형님 유교 석 동부 괴롭히다 경제력

            Sahara Skak | Bilen | Luke uk diar | NawigatsjuunCommonskategorii: SaharaWikivoyage raisfeerer: Sahara26° N, 13° O

            19. јануар Садржај Догађаји Рођења Смрти Празници и дани сећања Види још Референце Мени за навигацијуу