Why does initializing an extern variable inside a function give an error?

The reason defining an external variable inside a function does not make sense is the following: When you declare a symbol extern, you are telling the compiler to link all such occurrences of this value into the same symbol. Any occurences of extern int i; in your program would link to the externally defined i. … Read more

Java, What is the difference between assigning null to object and just declaration

It depends on the scope where you declare the variable. For instance, local variables don’t have default values in which case you will have to assign null manually, where as in case of instance variables assigning null is redundant since instance variables get default values. public class Test { Object propertyObj1; Object propertyObj2 = null; … Read more

Multiple declarations of x

No, this is not currently supported. The standard approach is to prefix each field with something unique to the particular datatype, e.g. p2x, p2y, p3x etc. The reason this isn’t supported is that each record field name implicitly generates a “selector” function, e.g. x :: Point2 -> Float. Having two fields with the same name … Read more

Redefinition allowed in C but not in C++?

Tentative definition is allowed in C but not in C++. A tentative definition is any external data declaration that has no storage class specifier and no initializer. C99 6.9.2/2 A declaration of an identifier for an object that has file scope without an initializer, and without a storage-class specifier or with the storage-class specifier static, … Read more

tech