Created
March 17, 2011 07:18
-
-
Save am0c/873960 to your computer and use it in GitHub Desktop.
test priority of * and ++ in c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <stdint.h> | |
| #include <string.h> | |
| #define TEST_STR "ABCD" | |
| #define TEST_STR_SIZE 5 | |
| #define TEST_INIT() \ | |
| origin = malloc( TEST_STR_SIZE ); \ | |
| p = origin; strncpy(p, TEST_STR, TEST_STR_SIZE); | |
| #define TEST_END() free(origin); | |
| #define TEST_PRINT(EXP) \ | |
| TEST_INIT(); \ | |
| printf(#EXP "\t"); \ | |
| printf("%s -> ", origin); \ | |
| printf("%s ( exp = %C,", origin, EXP); \ | |
| printf(" *p = %C, p = 0x%x )\n", *p, p); \ | |
| TEST_END(); | |
| int main() | |
| { | |
| uint8_t *origin; | |
| uint8_t *p; | |
| TEST_PRINT( *p ); | |
| TEST_PRINT( ++*p ); | |
| TEST_PRINT( ++*(p) ); | |
| TEST_PRINT( ++(*p) ); | |
| TEST_PRINT( *(++p) ); | |
| TEST_PRINT( *p++ ); | |
| TEST_PRINT( *(p)++ ); | |
| TEST_PRINT( (*p)++ ); | |
| TEST_PRINT( *(p++) ); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment