开发者

Are functions declared before or after calling them?

开发者 https://www.devze.com 2022-12-28 05:40 出处:网络
I was looking through someone\'s code one day and I was annoyed how they declared all their functions first and then later called them below. I guess I\'m use to Visual Studio\'s automatically generat

I was looking through someone's code one day and I was annoyed how they declared all their functions first and then later called them below. I guess I'm use to Visual Studio's automatically generated functions, that are made after you call them- and I was 开发者_C百科wondering, which way do you prefer? Or is there a standard on these kind of things?


I'm not sure what you mean by this. In C and C++, a function must be declared before it is called, otherwise the compiler won't know how to verify your arguments and return values.


I don't think it matters as the functions are all loaded into memory before execution begins. It's mostly a matter of style.

Personally I put miscellaneous functions that aren't part of a class definitions at the bottom of my code so it's easier to read.

That's just my $0.02 though.


Whatever Visual Studio do automatically can be considered a Microsoft standard. Not always the best standard, but a standard anyway =)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号