Why allow function declarations inside function bodies

Why does the syntax allow function declarations inside function bodies?

This raises a lot of questions about SO, where function declarations are mistaken for initialization variables, etc.

a object();

Not to mention the most unpleasant analysis.

Is there any precedent that is not easy to achieve with more general scope hiding features, such as namespaces and member spaces?

Is this for historical reasons?

Appendix: if for historical reasons inherited from C to limit the area, what is the problem that prohibits them?

+4
source share
2 answers

++ ++-, , C ++-. ++ ( "" API, - OpenGL cURL , C, , C )

, " - ", ++ . , , , , , - , , , NONE ++ - , ( - ).

, ++ - , , . static , , auto - , C, "" , , ( , 20 ).

+2

, C, , , , . , , , , .

- , , - , ++. ++ C. , , . , , ( gets(), ).

, . , -, , , .

, . , , , . , , , , . .

, , .. .. C ++ ( ) , "" " ". , , . , (, , , , ).

+2

Source: https://habr.com/ru/post/1599396/


All Articles