Skip to content

Commit

Permalink
intro-comparch/rotations: Change rotations parameter type
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
c7stef authored and teodutu committed Mar 19, 2024
1 parent 10fcfcf commit c18c1b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <stdio.h>

void rotate_left(int *number, int bits)
void rotate_left(unsigned int *number, int bits)
{
unsigned int bit_mask = -1;

Expand All @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

#include <stdio.h>

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;
Expand Down

0 comments on commit c18c1b9

Please sign in to comment.