Skip to content

[1.1.x] EEprom code cleanup#10711

Merged
thinkyhead merged 2 commits intoMarlinFirmware:bugfix-1.1.xfrom
GMagician:1.1.x-eeprom-code-cleanup
May 11, 2018
Merged

[1.1.x] EEprom code cleanup#10711
thinkyhead merged 2 commits intoMarlinFirmware:bugfix-1.1.xfrom
GMagician:1.1.x-eeprom-code-cleanup

Conversation

@GMagician
Copy link
Contributor

#10710 counterpart

@thinkyhead thinkyhead merged commit 02a79cc into MarlinFirmware:bugfix-1.1.x May 11, 2018
@GMagician
Copy link
Contributor Author

@thinkyhead just a question, what's the benefit of 'const' vs 'not const'?
does it shrink code?

@GMagician GMagician deleted the 1.1.x-eeprom-code-cleanup branch May 12, 2018 10:48
@thinkyhead
Copy link
Member

thinkyhead commented May 13, 2018

@GMagician — Adding const to function and method arguments can help with binding optimizations, especially for extern linkage that wouldn't otherwise know. Adding const to variables that won't change within a method or function can help compilers with load, spill, and loop invariance optimizations.

In terms of compilation, very often the compiler can tell after the first pass that a variable isn't being altered by the subsequent code, and it can optimize on the second pass just as it would if there was a const specifier, but I like to add const so human readers can see from the start that a value won't change, and so the compiler doesn't need to finish the first pass to know it won't change. And of course, it makes the compiler bark if you do try to alter it, which can sometimes be useful.

thinkyhead pushed a commit that referenced this pull request Sep 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants