From c18c1b94eed57f99a210edd0d737c100b8996db1 Mon Sep 17 00:00:00 2001 From: Cosmin Popa Date: Mon, 11 Mar 2024 21:09:24 +0200 Subject: [PATCH] intro-comparch/rotations: Change rotations parameter type Functions of the rotation task accepted `int` parameters, which can lead to unexpected behavior with bit operators. For more details, see systems-cs-pub-ro/iocla#171. Signed-off-by: Cosmin Popa --- .../binary-hex/drills/tasks/rotations/solution/rotations.c | 6 +++--- .../binary-hex/drills/tasks/rotations/support/rotations.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/chapters/intro-computer-architecture/binary-hex/drills/tasks/rotations/solution/rotations.c b/chapters/intro-computer-architecture/binary-hex/drills/tasks/rotations/solution/rotations.c index 1eaa3140..5f5f30d7 100644 --- a/chapters/intro-computer-architecture/binary-hex/drills/tasks/rotations/solution/rotations.c +++ b/chapters/intro-computer-architecture/binary-hex/drills/tasks/rotations/solution/rotations.c @@ -2,7 +2,7 @@ #include -void rotate_left(int *number, int bits) +void rotate_left(unsigned int *number, int bits) { unsigned int bit_mask = -1; @@ -13,7 +13,7 @@ void rotate_left(int *number, int bits) (*number) |= bit_mask; } -void rotate_right(int *number, int bits) +void rotate_right(unsigned int *number, int bits) { unsigned int bit_mask = -1; @@ -26,7 +26,7 @@ void rotate_right(int *number, int bits) int main(void) { - int number; + unsigned int number; number = 0x80000000; rotate_left(&number, 1); diff --git a/chapters/intro-computer-architecture/binary-hex/drills/tasks/rotations/support/rotations.c b/chapters/intro-computer-architecture/binary-hex/drills/tasks/rotations/support/rotations.c index 134ea8ec..929c3db4 100644 --- a/chapters/intro-computer-architecture/binary-hex/drills/tasks/rotations/support/rotations.c +++ b/chapters/intro-computer-architecture/binary-hex/drills/tasks/rotations/support/rotations.c @@ -2,14 +2,14 @@ #include -void rotate_left(int *number, int bits) +void rotate_left(unsigned int *number, int bits) { /* TODO */ (void) number; (void) bits; } -void rotate_right(int *number, int bits) +void rotate_right(unsigned int *number, int bits) { /* TODO */ (void) number;