try compile: #include <iostream> template <typename T, size_t Count> inline size_t countof ( const T (&) [Count] ) { return Count; } int main(int argc, char* argv[]) { struct { int x1; int x2;} x [100]; std::cout << countof(x) << std::endl; int y [101]; std::cout << countof(y) << std::endl; struct Z { int x1; int x2;} z [102]; std::cout << countof(z) << std::endl; std::cin.get(); return 0; } gcc info(gcc -v): Using built-in specs. Target: i386-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux Thread model: posix gcc version 4.1.2 20070626 (Red Hat 4.1.2-14)
Not a bug: type arguments to templates need to be *named* types with external linkage. The declaration of 'x' uses an unnamed structure, the declaration of 'z' a type of function-scope (and so internal) linkage. W.