Why does C++ regards as Static Languages [closed] - c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
From my recitation class -
In free variables (in function activation):
Static scoping: free variables are evaluated in the context of the defining occurrence of the function . include many you know: ML, Java,
C++.
Dynamic scoping: free variables in the function body are evaluated in the context of the function call
Static languages: Common
Include many you know: ML, Java, C++ Advantages modularity easier
variable access by the compiler
Can you give an example which describes why does C++ regards as Static languages ?

static language mean “statically typed language” . for example type of a variable can't be change and defined statically at compilation time.
But not because of any of reason you mentioned
int i = 10;
i in int can be char.
in opposite Python for example:
>>> x = "yourname" # x is pointing string
>>> x = 5 # x pointing number
So Python is an example of “dynamic typed language”

A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time. In C++, variables need to be defined before they are used so that compilers know what type they are, and hence is statically typed.
Please take a look at below articles
http://www.jvoegele.com/software/langcomp.html
http://existentialtype.wordpress.com/2011/03/19/dynamic-languages-are-static-languages/
http://en.wikipedia.org/wiki/Type_system
http://en.wikipedia.org/wiki/C%2B%2B

Related

C/C++ The purpose of static const local variable [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
In C and C++, what is the advantage of making a local const variable static? Assuming the initialization does not use other variables, is there any difference between preserving the value between calls, and setting the same constant value each call?
Could a valid C compiler ignore the static?
In C++, it avoids the construction/destruction between calls, but could there be any other benefit?
It doesn't take up stack-space may be a benefit if you have something like:
static const double table[fairly_large_number] = { .... };
Obviously, cost of construction can also be substantial enough that if the function is called a lot, there's good value in only constructing the object once.
Yes, and it is huge: a semantic benefit.
When you put const, you don't just mean the compiler shouldn't let you modify the variable. You make a bolder statement to whoever reads the code later: this won't ever change. Not even by a side effect where you give this variable as a pointer to another function.
Also, the compiler can take advantage of that new information and optimize it away in some situations, depending on the specific type you are dealing with.
(to be clear, I'm speaking here about const vs. non-const, not static vs. non-static.)
Edit: This SO answer is very informative too.

How to get the inializers of global variables with LLVM API [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm writing an LLVM pass which works on the LLVM IR code. A part of the objective is to read the initial values of global variables, where global variables could be of any type, from basic types to structs and classes. How do I achieve that?
If you invoke getInitializer on a GlobalVariable instance you get the initializer, of type Constant (though make sure you call hasInitializer or one of its sister methods first, to verify there's an initializer at all). Also IIRC global variables and constant are implemented as the same thing, so use isConstant to filter out the constants if you don't want them.
Of course, a Constant is the abstract base class; the actual type will be one of its children, which you can see in the diagram presented on the documentation page. You can query and get the actual constant type in the usual way, via isa / cast / dyn_cast, or you can use getType on it (a constant is a Value after all) and work from there.
Finally, to get all the global variables from a Module use either the global_begin/global_end iterators, or just use getGlobalList on it (it has its own iterator).

What is "Clean C" and how does it differ from standard C? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
What are the differences between pure C and C in C++?
What are some details about 'Clean C' on which Lua is based? What are those features?
Clean C is a term coined in Harbison & Steele book (C: A Reference Manual, Prentice Hall). A program is said to be written in Clean C if it can be compiled by a standard C compiler and a standard C++ compiler; and its execution would not produce different observable behavior from the two compilers (the issues of optimizations being irrelevant).
One that strikes me as being the most obvious is that in C++, you have to cast the return value of malloc. Also structs are automatically typedefed in C++.
Always use a C compiler for C code, not C++. C++ isn't perfectly compatible with C.
A few others differences may be:
In C, declaring void func(); declares a function that hasn't specifed what its arguments are, whereas in C++, void func(); is equivalent to the C void func(void)', taking no arguments;
Prototypes are required in C++, whereas it's generally just a warning in C;
The type of character constants (like 'a') is int in C and char in C++;
The type of string literals is char [] in C and const char [] in C++;
Some legitimate variable names in C, like class, are reserved keywords in C++.

Using const on local variables [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Similar to this question, what are the pro/cons to using const local variables like in this answer?
Personally, I like to use const for any declared object (I'm not sure the word "variable" applies) unless I'm actually going to modify it. It documents to the reader that the value of the object is always going to be whatever it was initialized to, which can make the code easier to follow and analyze.
(It can also help the compiler in some cases, but most compilers, when invoked in optimizing mode, are smart enough to notice that the object is never modified. And if you invoke the compiler in non-optimizing mode, you're telling it that you don't care much about performance.)
In fact, if I were going to design my own language, all declared objects would be const (read-only) by default unless you explicitly mark them as modifiable.

can any one tell me stream is a reserved keyword in c or c++; [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am using a function pointer variable named as "stream. SO i think it might create errors if it is a reserved keyword in c or c++.
Thanks in advance.
No, stream is not a keyword in either C or C++. See the accepted answer to Why is "array" marked as a reserved word in Visual-C++?
However, as pointed out by #pmg, this is not the whole story. Identifiers starting with str followed by a lowercase letter are reserved by the C standard for additional string functions. The gcc manual provides a handy list of identifiers to be avoided.
As other answers say stream is not a keyword.
However it IS technically a reserved identifier - all identifiers starting with str followed by a lower case letter are reserved for future additions to string.h
So in theory there's a possibility that a future version of C could introduce a standard function called stream and thus break your code. However the actual chance of that happening is probably tiny.