Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ cat hw058.c
- #include <stdio.h>
- inline
- static
- int p(int x) {
- return x * x;
- }
- #define P(X) (X * X)
- #define Q(X) ((X) * (X))
- int main(int argc, char const * argv[]) {
- int i = 3;
- printf("%d %d ", i, P(i + 1));
- printf("%d %d ", i, P(i++));
- printf("%d %d ", i, P(++i));
- printf("%d ", i);
- putchar('\n');
- i = 3;
- printf("%d %d ", i, Q(i + 1));
- printf("%d %d ", i, Q(i++));
- printf("%d %d ", i, Q(++i));
- printf("%d ", i);
- putchar('\n');
- i = 3;
- printf("%d %d ", i, p(i + 1));
- printf("%d %d ", i, p(i++));
- printf("%d %d ", i, p(++i));
- printf("%d ", i);
- putchar('\n');
- return 0;
- }
- # Compiling with clang
- # ##################################################################################
- $ clang -Wall -std=gnu18 -o ../../bin/hw058c hw058.c
- hw058.c:17:26: warning: unsequenced modification and access to 'i' [-Wunsequenced]
- printf("%d %d ", i, P(i++));
- ~ ^
- hw058.c:10:15: note: expanded from macro 'P'
- #define P(X) (X * X)
- ^
- hw058.c:18:25: warning: unsequenced modification and access to 'i' [-Wunsequenced]
- printf("%d %d ", i, P(++i));
- ~ ^
- hw058.c:10:15: note: expanded from macro 'P'
- #define P(X) (X * X)
- ^
- hw058.c:24:26: warning: unsequenced modification and access to 'i' [-Wunsequenced]
- printf("%d %d ", i, Q(i++));
- ~ ^
- hw058.c:11:16: note: expanded from macro 'Q'
- #define Q(X) ((X) * (X))
- ^
- hw058.c:25:25: warning: unsequenced modification and access to 'i' [-Wunsequenced]
- printf("%d %d ", i, Q(++i));
- ~ ^
- hw058.c:11:16: note: expanded from macro 'Q'
- #define Q(X) ((X) * (X))
- ^
- hw058.c:31:26: warning: unsequenced modification and access to 'i' [-Wunsequenced]
- printf("%d %d ", i, p(i++));
- ~ ^
- hw058.c:32:25: warning: unsequenced modification and access to 'i' [-Wunsequenced]
- printf("%d %d ", i, p(++i));
- ~ ^
- 6 warnings generated.
- # Compiling with gcc
- # ##################################################################################
- $ gcc-9 -Wall -std=gnu18 -o ../../bin/hw058g hw058.c
- hw058.c: In function 'main':
- hw058.c:17:26: warning: operation on 'i' may be undefined [-Wsequence-point]
- 17 | printf("%d %d ", i, P(i++));
- | ~^~
- hw058.c:10:15: note: in definition of macro 'P'
- 10 | #define P(X) (X * X)
- | ^
- hw058.c:17:26: warning: operation on 'i' may be undefined [-Wsequence-point]
- 17 | printf("%d %d ", i, P(i++));
- | ~^~
- hw058.c:10:15: note: in definition of macro 'P'
- 10 | #define P(X) (X * X)
- | ^
- hw058.c:18:25: warning: operation on 'i' may be undefined [-Wsequence-point]
- 18 | printf("%d %d ", i, P(++i));
- | ^~~
- hw058.c:10:15: note: in definition of macro 'P'
- 10 | #define P(X) (X * X)
- | ^
- hw058.c:18:25: warning: operation on 'i' may be undefined [-Wsequence-point]
- 18 | printf("%d %d ", i, P(++i));
- | ^~~
- hw058.c:10:15: note: in definition of macro 'P'
- 10 | #define P(X) (X * X)
- | ^
- hw058.c:24:26: warning: operation on 'i' may be undefined [-Wsequence-point]
- 11 | #define Q(X) ((X) * (X))
- | ~~~
- ......
- 24 | printf("%d %d ", i, Q(i++));
- hw058.c:11:16: note: in definition of macro 'Q'
- 11 | #define Q(X) ((X) * (X))
- | ^
- hw058.c:24:26: warning: operation on 'i' may be undefined [-Wsequence-point]
- 11 | #define Q(X) ((X) * (X))
- | ~~~
- ......
- 24 | printf("%d %d ", i, Q(i++));
- hw058.c:11:16: note: in definition of macro 'Q'
- 11 | #define Q(X) ((X) * (X))
- | ^
- hw058.c:25:25: warning: operation on 'i' may be undefined [-Wsequence-point]
- 11 | #define Q(X) ((X) * (X))
- | ~~~
- ......
- 25 | printf("%d %d ", i, Q(++i));
- hw058.c:11:16: note: in definition of macro 'Q'
- 11 | #define Q(X) ((X) * (X))
- | ^
- hw058.c:25:25: warning: operation on 'i' may be undefined [-Wsequence-point]
- 11 | #define Q(X) ((X) * (X))
- | ~~~
- ......
- 25 | printf("%d %d ", i, Q(++i));
- hw058.c:11:16: note: in definition of macro 'Q'
- 11 | #define Q(X) ((X) * (X))
- | ^
- hw058.c:31:26: warning: operation on 'i' may be undefined [-Wsequence-point]
- 31 | printf("%d %d ", i, p(i++));
- | ~^~
- hw058.c:32:25: warning: operation on 'i' may be undefined [-Wsequence-point]
- 32 | printf("%d %d ", i, p(++i));
- | ^~~
- # Running clang binary
- # ##################################################################################
- $ ../../bin/hw058c
- 3 7 3 12 5 42 7
- 3 16 3 12 5 42 7
- 3 16 3 9 4 25 5
- # Running gcc binary
- # ##################################################################################
- $ ../../bin/hw058g
- 3 7 5 12 7 49 7
- 3 16 5 12 7 49 7
- 3 16 4 9 5 25 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement