I know one can probably program your entire life without knowing this, but I can't. Could someone please enlighten me as to why the compiler needs a forward declaration of functions, variables etc and why it cares so much about their prototypes?
2 replies to this topic
#1
Posted 25 January 2012 - 02:05 PM
|
|
|
#2
Posted 25 January 2012 - 02:53 PM
That's part of a strongly typed language. As far as variables are concerned, the compiler needs to know their types ahead of time because it has to allocate a specific amount of memory depending on how large that type is, and it has to interpret the bits found at that memory location in a certain way, because different types are represented differently. As far as functions go, these have specific signatures because their parameters are allocated in much the same way as variables: areas of memory on the program stack. It also allows the compiler to reject unsafe operations on certain types at compile time, instead of causing the program to crash at runtime. In other words, it's a method of guaranteeing program accuracy.
If you want to learn more about strong type systems, you might try studying type theory: Type theory - Wikipedia, the free encyclopedia
Computer type systems find their roots in lambda calculus, so there's a deep rooted structure in mathematics, not just something somebody came up with one day. :)
If you want to learn more about strong type systems, you might try studying type theory: Type theory - Wikipedia, the free encyclopedia
Computer type systems find their roots in lambda calculus, so there's a deep rooted structure in mathematics, not just something somebody came up with one day. :)
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#3
Posted 29 January 2012 - 11:26 PM
Many thanks, great response :thumbup1:
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









