Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 22484

Check if array is a VLA at compile-time

$
0
0

@Lundin shows how to check if a passed expression is an array at compile-time here: Lvalue conversion of _Generic controlling expression involving array clang warning wrong?:

#define IS_ARRAY(T)            \  _Generic( &(T),              \    typeof(*T) (*)[]  : true,  \    default           : false  \  )

Can we further differentiate between an array which has variable length array type and one which does not?

Why do I need this? I have a generic SWAP() that does not work for VLAs. I would like to check at compile-time (static_assert) whether a VLA was passed to SWAP() and guide the user to use another variant of SWAP() that work for VLAs. That would be better understandable than a compiler error about having a variable-length array in a compound-literal...


Viewing all articles
Browse latest Browse all 22484

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>