A similar question was previously asked, but none of the answers provided what I was looking for.
I find it difficult to decide where consts should be located in the function. I know that many people put them at the top, but if you put them as close as possible to where they are used, you will reduce the range of the code. I.e.
void f() { const FOO = 3; ...// some code if ( bar > FOO ) { ...// do stuff } }
or
void f() { ...// some code const FOO = 3; if ( bar > FOO ) { ...// do stuff } }
I tend to use const at the top in small functions and keep the range as close as possible to large functions, but I was wondering what these styles / thoughts of others are.
In the lowest possible volume and immediately before their first use.
/, , .
, ( "" ) , . , const , , , , .
.
, , "" "" .
, . , .
, , , (, ).
, , ( const), , , .
C C99 . , C-. , Code Complete , , C ++.
, C ++ , .
, , , , . , . , ++ . , . , . + , .
, , . const? const int n = 3; , const, const char * s = "FOO";? , ? const char * const s = "FOO";? , , , , , const , , .
Source: https://habr.com/ru/post/1724676/More articles:Hibernate is much faster when running its own query - javaAn optimized way to check site ownership (using javascript?) - javascriptZend_ACL with a modular structure? - zend-frameworkAircraft planning task since 2009 in the final of ACM-ICPC World Finals - algorithmimg src & jQuery? - jqueryС++: вопрос инициализации новичка - c++arraylist with objects does not support values - javaDelayed LINQ to SQL Labels with Delay - linq-to-sqlIs Tie :: File lazily loading a file? - arraysKeyboard input in Tcl - tclAll Articles