Skip to content

Commit

Permalink
Change type_compatible() so that void is not compatible with
Browse files Browse the repository at this point in the history
anything, including itself.
  • Loading branch information
Warren Toomey committed Jan 6, 2020
1 parent 32dacf2 commit bea0c06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions 12_Types_pt1/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,12 @@ the types on either side. Here's the code:
// If onlyright is true, only widen left to right.
int type_compatible(int *left, int *right, int onlyright) {
// Voids not compatible with anything
if ((*left == P_VOID) || (*right == P_VOID)) return (0);
// Same types, they are compatible
if (*left == *right) { *left = *right = 0; return (1);
}
// Voids not compatible with anything
if ((*left == P_VOID) || (*right == P_VOID)) return (0);
// Widen P_CHARs to P_INTs as required
if ((*left == P_CHAR) && (*right == P_INT)) {
Expand Down
7 changes: 4 additions & 3 deletions 12_Types_pt1/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
// If onlyright is true, only widen left to right.
int type_compatible(int *left, int *right, int onlyright) {

// Voids not compatible with anything
if ((*left == P_VOID) || (*right == P_VOID))
return (0);

// Same types, they are compatible
if (*left == *right) {
*left = *right = 0;
return (1);
}
// Voids not compatible with anything
if ((*left == P_VOID) || (*right == P_VOID))
return (0);

// Widen P_CHARs to P_INTs as required
if ((*left == P_CHAR) && (*right == P_INT)) {
Expand Down

0 comments on commit bea0c06

Please sign in to comment.