Skip to content

Instantly share code, notes, and snippets.

@yugui
Created April 15, 2020 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yugui/514af73378d14db74ffd74f3c2f418d3 to your computer and use it in GitHub Desktop.
Save yugui/514af73378d14db74ffd74f3c2f418d3 to your computer and use it in GitHub Desktop.
#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