Created
April 15, 2020 04:13
-
-
Save yugui/514af73378d14db74ffd74f3c2f418d3 to your computer and use it in GitHub Desktop.
This file contains 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> | |
#define IS_ARRAY(ary) ((void*)(ary) == (void*)&(ary)) | |
#define TEST(ary, expected) \ | |
printf( \ | |
"%s:%u: expected %s, actually %s\n", \ | |
__FILE__, \ | |
__LINE__, \ | |
expected, \ | |
(IS_ARRAY(ary) ? "array" : "ptr")) | |
struct S { | |
int ary[3]; | |
int *ptr; | |
int c99flexible[]; | |
}; | |
void func(int a[3], int b[], int* c, struct S* s) { | |
TEST(a, "ptr"); | |
TEST(b, "ptr"); | |
TEST(c, "ptr"); | |
TEST(s->ary, "array"); | |
TEST(s->ptr, "ptr"); | |
TEST(s->c99flexible, "array"); | |
} | |
int main() { | |
int ary[3]; | |
int *ptr; | |
struct S s = {{1,2,3}, ptr}; | |
TEST(ary, "array"); | |
TEST(ptr, "ptr"); | |
func(ary, ary, ptr, &s); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment