Computers and Technology

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;

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 05:00, mathman783
Which two editions of windows 7 support 64 bit cpus? choose two out of professional, business, starter, or home premium.
Answers: 1
image
Computers and Technology, 23.06.2019 03:30, mem81
How can you repin an image on your pinterest pin board a. click on the "repin" button b. click on the "add pin" button c. click on the "upload a pin" button d. click on the "save pin" button.
Answers: 2
image
Computers and Technology, 23.06.2019 10:00, karissanichole18
Install and use wireshark program ( send back screen shots and other vital information) case project 3-2: decode a tcp segment in a wireshark capture in this chapter, you walked through tcp segment to interpret the data included in its header. in this project, you use wireshark to capture your own http messafes, examine the tcp headers, and practice interpreting the data you'll find there. 1. open wireshark and snap the window to one side of your screen. open a browser and snap that window to the other side of your screen so you can see both windows.
Answers: 2
image
Computers and Technology, 24.06.2019 17:30, bxbykay1
Looking at the electroscope, describe how you can cause the two leaves at the bottom to repel each other and stay that way
Answers: 3
Do you know the correct answer?
The c language allows you to define new names for existing types using typedefs. here is some exampl...

Questions in other subjects: