Primary:
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Sets:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Miscellaneous:
[2001S]
[98F]
[SamR]
[Glimmer Labs]
Back to Type Equivalence. On to Coding Style.
Held Friday, October 18, 2002
Summary
Today we continue our explorations of type checking and type equivalence with some examples from C and some further questions.
Notes
Node object or build a
separate class for each nonterminal. I think it's more elegant
to build a separate class for each nonterminal, but I'd probably
write a program to do that for me (i.e., with something that translates
text files to class files). I would start with the generic
Note in either case.
Overview
I thought you might enjoy this quote from Kernighan & Ritchie (2nd edition, p. 198).
Many operators cause conversions and yield result types in a similar way. The effect is to bring operands into a common type, which is also the type of the result. This pattern is called the usual arithmetic conversions
First, if either operand is a
long double, the other operand is converted to along double.Otherwise, if either operand is a
double, the other is converted todouble.Otherwise, if either operand is a
float, the other is converted tofloat.Otherwise, the integral promotions are performed on both operands; then, if either operand is
unsigned long int, the other is converted tounsigned long int.Otherwise, if one operand is
long intand the other isunsigned int, the effect depends on whether along intcan represent all values of anunsigned int; if so, theunsigned intoperand is converted tolong int; if not, both are converted tounsigned long int.Otherwise, if one operand is
long int, the other is converted tolong int.Otherwise, if one operand is
unsigned int, the other is converted tounsigned int.Otherwise, both operands have type
int.
Wasn't that fun?
constantsin a type.
#include <stdio.h>
int printval(int val)
{
printf("%d\n", val);
return val;
}
int main() {
int x;
x = printval(2) + printval(3) * printval(5);
(void) printval(x);
return 0;
}
i++ - i++?
Thursday, 29 August 2002 [Samuel A. Rebelsky]
Friday, 18 October 2002 [Samuel A. Rebelsky]
Back to Type Equivalence. On to Coding Style.
Primary:
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Sets:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Miscellaneous:
[2001S]
[98F]
[SamR]
[Glimmer Labs]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Fri Dec 6 10:38:20 2002.
The source to the document was last modified on Fri Oct 18 10:19:07 2002.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2002F/Outlines/outline.22.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby