Programming Languages 2. In your local implementation of C, what is the limit on
ID: 651769 • Letter: P
Question
Programming Languages
2. In your local implementation of C, what is the limit on the size of integers (describe how you found the answer)? What happens in the event of arithmetic overflow? What are the implications of size limits on the portability of programs from one machine/compiler to another? Find out how the answers differ to these questions for any one of the following languages: Java, Ada, Pascal or Scheme?
3. Indicate the binding time (e.g., when the language is designed, when the program is linked, when the program starts execution, etc.,) for each of the following decisions in your favorite programming language and implementation. Explain any answers you think are open to interpretation.
o The number of built-in functions (abs, cosine, etc.).
o The variable declaration that corresponds to a particular variable reference(say, its use in an expression).
o The maximum length allowed for a constant (literal) character string.
o The referencing environment for a subroutine that is passed as a parameter o The address of a particular library routine.
o The total amount of space occupied by program code and data.
4. Give two conceptually different concrete examples drawn from programming languages with which you are familiar in which a variable or some other object is live but not in scope. (Hint: consider how different abstraction and information hiding mechanisms may affect the visibility and accessibility of objects.)
Explanation / Answer
================================================================================
2. In your local implementation of C, what is the limit on the size of integers (describe how you found the answer)?
What happens in the event of arithmetic overflow? What are the implications of size limits on the portability of programs
from one machine/compiler to another? Find out how the answers differ to these questions for any one of the following languages:
Java, Ada, Pascal or Scheme?
Ans:
The range of int in C is depends on operating system.
For 16 bit operating system the size is -32,768 to 32,767.
For 32 bit operating system the size is -2,147,483,648 to 2,147,483,647.
In C , if an arithmetic overflow occurs the program terminates and stops responding.
Example for arithmetic overflow is divide by zero, array index out of bound.
For other languages like Java:
The default int size is 32 bits.
And Java provides exceptions mechanism to handle the arithmatic overflows using
predefined classes.
================================================================================
3. Indicate the binding time (e.g., when the language is designed, when the program is linked, when the program starts execution, etc.,)
for each of the following decisions in your favorite programming language and implementation. Explain any answers you think are open to interpretation.
o The number of built-in functions (abs, cosine, etc.).
o The variable declaration that corresponds to a particular variable reference(say, its use in an expression).
o The maximum length allowed for a constant (literal) character string.
o The referencing environment for a subroutine that is passed as a parameter o The address of a particular library routine.
o The total amount of space occupied by program code and data.
Ans:
The binding time is defines by the following times.
----------------------------------------------------
Compile time.
The compiler translates symbolic addresses to absolute addresses.
If you know at compile time where the process will reside in memory, then absolute code can be generated (Static).
Load time.
The compiler translates symbolic addresses to relative (relocatable) addresses.
The loader translates these to absolute addresses. If it is not known at compile time where the process will reside in memory,
then the compiler must generate relocatable code (Static).
Execution time.
If the process can be moved during its execution from one memory segment to another,
then binding must be delayed until run time. The absolute addresses are generated by hardware.
Most general-purpose OSs use this method (Dynamic).
o The number of built-in functions (abs, cosine, etc.). :
- Load time
o The variable declaration that corresponds to a particular variable reference(say, its use in an expression).
- Compile time
o The maximum length allowed for a constant (literal) character string.
- Compile time
o The referencing environment for a subroutine that is passed as a parameter
- Compile time
o The address of a particular library routine.
- Load time
o The total amount of space occupied by program code and data.
- Execution time ; Since data is available only when code is executed
================================================================================
4. Give two conceptually different concrete examples drawn from programming languages with which you are
familiar in which a variable or some other object is live but not in scope.
(Hint: consider how different abstraction and information hiding mechanisms may affect the visibility and accessibility of objects.)
Ans:
For the given question i am selecting java languange.
In Java: The variable can live but it wont be in scope. This can be achieved by using
abstraction and encapsulation mechanism.
If you have the private varible which is declared in class A
class A {
private int data;
public int getData()
{
return data;
}
}
When you instatiate object , you cannot access the private data directly, even you have scope.
This can be achieved only by using public member functions.
Similarlly for abstraction also ,It will hide all unnecessary features showing only esentials.
For example : If keyboard of computer does not even know to the end user how it is working.
==================================================================================
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.