Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 8
    Between the last two I decide based on whether the two values must really be the same type (bool previousInputValue, presentInputValue;) or if they just happen to be the same type now but don't really need to be (uint8_t height, width; might turn into uint8_t height; uint16_t width; in the future and should have been uint8_t height; uint8_t width; to begin with). Commented Jun 17, 2015 at 15:08
  • Because writing uint8_t height; uint16_t width; instead of uint8_t height, width; saves 10 characters in the future. :-) you can of course do it however you like. Just make sure you make it easily read. So the last form is the most explicit. Commented Aug 14, 2016 at 20:56
  • 2
    The last form is certainly the most explicit at stating the type of each variable and making it clear that each one is initialized. That said, it is not explicit about whether or not column and row are expected to be the same type or not. Perhaps we would both prefer the explicitness of int presentValue = 0; typeof(presentValue) previousValue = presentValue;, but I believe that typeof() is a non-standard GCC extension. Commented Aug 14, 2016 at 21:20
  • 1
    @altendky: C++11 introduced decltype as a portable version of GNU C typeof. So decltype (width) height = 0; works, but requires more mental effort to read. Commented Oct 10, 2022 at 15:41