Trivial: Make CBlockIndex param const in ContextualCheckBlockHeader and ContextualCheckBlock #8347

pull jtimon wants to merge 1 commits into bitcoin:master from jtimon:0.12.99-consensus-const-lost changing 2 files +4 −4
  1. jtimon commented at 11:42 PM on July 16, 2016: contributor

    I always included this in my longest consensus branches because it was free to do so when you where changing the function's footprint anyway, but I lost it in rebase because I though it was purely a question of style (using const before or after). It turns out it is not just about complying with our current style: the parameter could be const but is not.

    Libconsensus related: ping @NicolasDorier @kanzure (feel free to ask to be added to this little list).

  2. Trivial: Make CBlockIndex param const in ContextualCheckBlockHeader and ContextualCheckBlock 6f3d616dc8
  3. jtimon force-pushed on Jul 16, 2016
  4. petertodd commented at 12:49 AM on July 17, 2016: contributor

    Concept ACK

  5. NicolasDorier commented at 3:21 AM on July 17, 2016: contributor

    ACK 6f3d616 (I thought there was a subtle difference between const CBlockIndex* pindexPrev and CBlockIndex* const pindexPrev that only C Jedi could understand, but it is fine)

  6. sipa commented at 6:17 AM on July 17, 2016: member

    @NicolasDorier: no, the first is a pointer to a const CBlockIndex. The second is a const pointer to a non-const CBlockIndex.

  7. sipa commented at 6:18 AM on July 17, 2016: member

    utACK

  8. dcousens commented at 6:21 AM on July 17, 2016: contributor

    utACK 6f3d616

  9. jtimon referenced this in commit 3c459f84ef on Jul 17, 2016
  10. jtimon commented at 11:56 AM on July 17, 2016: contributor

    @NicolasDorier: no, the first is a pointer to a const CBlockIndex. The second is a const pointer to a non-const CBlockIndex.

    Actually, I don't think the const after does anything at all. Note that the declaration of ContextualCheckBlock didn't had any const in it, but the definition had it. It seems to me that the const in the definition must be ignored or else it wouldn't link for not matching the declaration.

  11. jonasschnelli commented at 12:04 PM on July 17, 2016: contributor

    ACK 6f3d616

  12. jonasschnelli added the label Refactoring on Jul 17, 2016
  13. jtimon commented at 12:06 PM on July 17, 2016: contributor

    Extending on the meta discussion, if I understand it correctly, it works like this:

    1. const Object* and const Object& are equivalent: you can neither change the state of the object nor change the address in memory the pointer is pointing to.

    2. With Object& you can change the state of the object, but not the pointer.

    3. With Object* you can both change the state of the object and change the memory address the pointers points to.

  14. instagibbs commented at 2:03 PM on July 18, 2016: member

    @jtimon (possibly misunderstanding your point) const Object* is only const on the object, not the pointer itself. The pointer itself can be modified.

    that said, utACK https://github.com/bitcoin/bitcoin/commit/6f3d616dc8d6840c2293ffadd8cc3209f1100193

  15. jtimon commented at 2:40 PM on July 18, 2016: contributor

    @instagibbs so in my little example, ptr will be &B after calling the function? https://0bin.net/paste/qfBVja+dQAt-R56h#BbZHm3Ynf3rkl01YLVU+tgPKggTbeVMvarzFk-LhFDN

  16. sipa commented at 2:49 PM on July 18, 2016: member

    @jtimon You have two variables named ptr there. A global one, and one inside testFunction. When testFunction is called, its argument (ptr) is evaluated (resulting in &A), and the value &A is passed to the function, which binds it to the parameter ptr. Executing ptr = &B modifies the local variable ptr, but not the global one (as the argument is passed by value, not by reference).

  17. jtimon referenced this in commit 70b7f18732 on Jul 18, 2016
  18. jtimon referenced this in commit 3ae669e61b on Jul 19, 2016
  19. jtimon commented at 7:44 PM on July 20, 2016: contributor

    @sipa Right, which is what I was saying to @instagibbs , that the pointer would not be modified with const. But if you s/const Object* ptr/Object* ptr/ then the local ptr will be changed. Right? Is my comment #8347 (comment) incorrect ?

  20. laanwj commented at 12:31 PM on July 21, 2016: member

    utACK 6f3d616

  21. laanwj merged this on Jul 21, 2016
  22. laanwj closed this on Jul 21, 2016

  23. laanwj referenced this in commit 381917f610 on Jul 21, 2016
  24. codablock referenced this in commit e24377fa9a on Sep 19, 2017
  25. codablock referenced this in commit 7a0f19e125 on Dec 29, 2017
  26. codablock referenced this in commit 9a91ddb417 on Jan 8, 2018
  27. andvgal referenced this in commit 65a81f5865 on Jan 6, 2019
  28. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-17 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me