The C language allows you to define new names for existing types using typedefs
ID: 3683902 • Letter: T
Question
The C language allows you to define new names for existing types using typedefs. Here is some example code that uses typedefs:
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:
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.
Assume that the following productions have been added to the grammar for the cats language:
What other productions need to be changed and/or added to the cats grammar to allow typedefs?
Explanation / Answer
Productions need to be changed and/or added to the cats grammar to allow typedefs uses declspecs_ts after_type_declaration.
typedef int data1;
typedef float data2;
{
data1 data2;
}
declspecs_nots notype_declaration
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.