Skip to content

Instantly share code, notes, and snippets.

@am0c
Created March 17, 2011 07:18
Show Gist options
  • Select an option

  • Save am0c/873960 to your computer and use it in GitHub Desktop.

Select an option

Save am0c/873960 to your computer and use it in GitHub Desktop.
test priority of * and ++ in c
#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