Questions tagged [declarations]

For questions related to declarations, constructs that introduce a new variable, function, method, class, type, or other program entity

Filter by
Sorted by
Tagged with
8 votes
4 answers
2k views

Why are mixed declarations more challenging to implement than forcing all declarations to be at the top of a scope?

C89 had a requirement that all declarations must appear at the top of the scope before any statements: ...
user16217248's user avatar
  • 7,535
4 votes
6 answers
1k views

Why tag function definition with def, fn, fun, func or function etc?

What makes it hard for compilers/interpreters that we need to tag the function definition with keyword fn/fun/func/function? I can understand that types for numbers: int, int32, float32, float64... ...
Anubhav's user avatar
  • 173
12 votes
3 answers
2k views

Is type checking usually preceded by a pass that looks at just names and declarations?

Let's say I've parsed a file of code into an AST, and now I want to walk the AST and type check it. My AST nodes have a signature like this (C++) ...
Rob N's user avatar
  • 1,073
-1 votes
1 answer
148 views

What is a good universal naming syntax? [closed]

Lots of languages do not clearly separate the declaration of a variable, function or type from naming that entity, or if they do it does not have a uniform syntax. Consider C++: Naming a variable: <...
G. Sliepen's user avatar
6 votes
3 answers
292 views

Why is implicitly declaring functions problematic?

I believe one used to be able to do this in C: int main(void) { return printf("Hello world!") > 0; } Now this became invalid in C99, and one must ...
user16217248's user avatar
  • 7,535
4 votes
3 answers
365 views

What are the advantages and disadvantages of only allowing declarations at the top level?

Some languages, such as C++ and Java, have grammar restrictions where code that is not a declaration or import statement cannot be outside of a function. However, variables, functions, and classes can ...
FireTheLost's user avatar
  • 1,583
6 votes
2 answers
287 views

Why do newer languages allow implicit variable declarations?

For me, one of the best things to happen to FORTRAN was the introduction of the LOGICAL*1 type. I quickly discovered that putting ...
Ray Butterworth's user avatar