subject

The c language allows you to define new names for existing types using typedefs. here is some example code that uses typedefs:
typedef int money;
int x;
money y;
typedef money dollars;
dollars z;
x = 10;
y = x; // ok because x and y are of type int
z = y; // ok because y and z are of type int
the first typedef defines money to be a synonym for int. any declaration that follows this typedef can use money instead of int. the second typedef defines dollars to be a synonym for money, which makes it a synonym for int. any declaration that follows this typedef can use dollars instead of int.
typedefs can also be used with struct types:
struct pair {
int x;
int y;
};
typedef struct pair point;
point p;
a typedef can occur anywhere that a variable declaration (local or global) can occur. the usual c scoping rules apply to the names in typedefs. note that typedef int money; is considered to be a declaration of the name money and that both money x; and typedef money dollars; are considered to be uses of the name money.
question 2
now consider the name-analysis phase of the compiler. note that, in addition to the usual errors for multiply-defined names and for uses of undefined names, the name analyzer must enforce the following rules:
the declaration typedef t xxx; is an error if t is not a built-in type (e. g., int, bool) or a struct type (in which case t will be of the form: struct ttt) or a new type defined by a previous typedef in the current or an enclosing scope.
the declaration typedef t xxx; is an error if xxx has already been declared in the current scope (as a variable, function, parameter, or new type).
a variable, function, or parameter can only be declared to be of type t if t is either a built-in type or a new type defined by a previous typedef in the current or an enclosing scope. (a variable can still be declared to be of type struct ttt as before.)
answer each of the following questions:
what information should be stored with each name in the symbol table?
what should be done to process a typedef: typedef t xxx; ?
what should be done to process a declaration of a variable, function, or parameter named xxx and declared to be of type t?
what should be done to process the use of a name xxx in a statement?
illustrate your answer by showing the entries that would be in the symbol table after processing the following declarations:
struct monthdayyear {
int month;
int day;
int year;
};
typedef struct monthdayyear date;
date today;
typedef int dollars;
dollars salary;
typedef dollars moredollars;
moredollars md;
int d;

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 22:20, kaiyerecampbell95
Pp 4.1 design and implement a class called sphere that contains instance data that represents the sphere’s diameter. define the sphere constructor to accept and initialize the diameter and include getter and setter methods for the diameter. include methods that calculate and return the volume and surface area of the sphere (see pp 3.5 for the formulas). include a tostring method that returns a one-line description of the sphere. create a driver class called multisphere, whose main method instantiates and updates several sphere objects.
Answers: 1
image
Computers and Technology, 23.06.2019 00:00, destinysmithds7790
Suppose you have 9 coins and one of them is heavier than others. other 8 coins weight equally. you are also given a balance. develop and algorithm to determine the heavy coin using only two measurements with the of the balance. clearly write your algorithm in the form of a pseudocode using the similar notation that we have used in the class to represent sorting algorithms
Answers: 1
image
Computers and Technology, 23.06.2019 10:30, badpotterchris
How would you categorize the software that runs on mobile devices? break down these apps into at least three basic categories and give an example of each.
Answers: 1
image
Computers and Technology, 23.06.2019 12:00, daelinrobinson
If you're using an existing powerpoint presentation that will receive new slides based on a word outline, select the a. slide that will appear after the new slides. b. first slide in the presentation. c. slide that will appear before the new slides. d. last slide in the presentation.
Answers: 2
You know the right answer?
The c language allows you to define new names for existing types using typedefs. here is some exampl...

Questions in other subjects:

Konu
Mathematics, 27.10.2020 19:40