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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 21:00
So im doing this school challenge and the teachers said whats the average text a student gets a day so i need to get about 20 in a day but dont know how can you guys 2163371293
Answers: 2
question
Computers and Technology, 22.06.2019 21:30
Nathan wants to create multiple worksheet containing common formatting styles for his team members. which file extension him to save these worksheets? nathan to create multiple worksheets with common styles. he needs to save them with the extension.
Answers: 1
question
Computers and Technology, 22.06.2019 22:00
Perform the following tasks: a. create a class named testclass that holds a single private integer field and a public constructor. the only statement in the constructor is one that displays the message “constructing”. write a main()function that instantiates one object of the testclass. save the file as testclass.cpp in the chapter 08 folder. run the program and observe the results. b. write another main()function that instantiates an array of 10 testclass objects. save the file as test class array.c . run this program and observe the results.
Answers: 1
question
Computers and Technology, 24.06.2019 00:30
The best definition of an idiom is a. a word or phrase that describes a noun b. a word or phrase describing a verb c. a phrase containing figurative language in which the word expresses a different idea from its exact meaning d. a phrase that compares two unlike objects or ideas
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