Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

As the title might look very confusing, let me give you an example:

typedef bool foo[2];
typedef foo bar[4];
bar what_am_i;

So, is what_am_i a [4][2] dimensional array as I presume, or a [2][4] dimensional array?

share|improve this question

It's bool[4][2] You can verify it by static_assert:

static_assert(std::is_same<decltype(what_am_i), bool[4][2]>::value, "");
static_assert(std::is_same<decltype(what_am_i), bool[2][4]>::value, ""); // failed
share|improve this answer

foo is an array with 2 elements of type bool, i.e. bool[2].

bar is an array with 4 elements of type foo, i.e. foo[4], each element is a bool[2].

Then what_am_i is bool[4][2].

share|improve this answer

In order to complete @Slardar Zhang's C++ answer for C:

It's bool[4][2].

You can verify it by either one of the following:

  • sizeof(what_am_i)/sizeof(*what_am_i) == 4
  • sizeof(*what_am_i)/sizeof(**what_am_i) == 2
share|improve this answer

After inspecting the variable through the debugger, I found that I was right - what_am_i is a [4][2] dimensional array.

share|improve this answer

When you don't know the type of a variable, one of the easy ways is this trick:

 template<class T> struct tag_type{using type=T;};
 template<class T> constexpr tag_type<T> tag{};

then do this:

 tag_type<void> t = tag<some_type>;

almost every compiler will spit out a reasonably readable "you cannot assign tag_type<full_unpacked_type> to tag_type<void>" or somesuch (presuming your type isn't void that is).

You can also verify you have a good guess with

tag_type<your_guess> t = tag<some_type>;

sometimes you'll want to generate some_type via decltype(some_expression).

share|improve this answer
    
or you can cout << typeid(what_am_i).name()—after piping through c++filt, it reports bool [4][2]. – Kundor 19 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.