Recently in c_cxx Category

Ubuntu 12.04 LTS上

默认的yar-c从github上clone下来之后, configure之后make默认报错

(Ubuntu 14.04.1LTS不会报错)

if /bin/sh ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I. -I/usr/include/ -I/usr/include/    -g -O2 -MT yar_server.lo -MD -MP -MF ".deps/yar_server.Tpo" -c -o yar_server.lo yar_server.c; \
    then mv -f ".deps/yar_server.Tpo" ".deps/yar_server.Plo"; else rm -f ".deps/yar_server.Tpo"; exit 1; fi
./libtool: 1: ./libtool: X--tag=CC: not found
./libtool: 884: ./libtool: libtool: ignoring unknown tag : not found
./libtool: 1: ./libtool: X--mode=compile: not found
./libtool: 1017: ./libtool: *** Warning: inferring the mode of operation is deprecated.: not found
./libtool: 1018: ./libtool: *** Future versions of Libtool will require --mode=MODE be specified.: not found
./libtool: 1: ./libtool: Xgcc: not found
./libtool: 1: ./libtool: X-DHAVE_CONFIG_H: not found
./libtool: 1: ./libtool: X-I.: not found
./libtool: 1: ./libtool: X-I.: not found
./libtool: 1: ./libtool: X-I.: not found
./libtool: 1: ./libtool: X-I/usr/include/: not found
./libtool: 1: ./libtool: X-I/usr/include/: not found
./libtool: 1: ./libtool: X-g: not found
./libtool: 1: ./libtool: X-O2: not found
./libtool: 1: ./libtool: X-MT: not found
./libtool: 1: ./libtool: Xyar_server.lo: not found
./libtool: 1: ./libtool: X-MD: not found
./libtool: 1: ./libtool: X-MP: not found
./libtool: 1: ./libtool: X-MF: not found
./libtool: 1: ./libtool: X.deps/yar_server.Tpo: not found
./libtool: 1: ./libtool: X-c: not found
./libtool: 1: ./libtool: Xyar_server.lo: not found
./libtool: 1218: ./libtool: libtool: compile: cannot determine name of library object from `': not found
make[1]: *** [yar_server.lo] Error 1

原因是自带的autoconf工具集和系统的版本相差太大, 尤其是libtool的


进入, 执行:%s/$echo/$ECHO/g







| No Comments | No TrackBacks


template<typename T, size_t N>
char (&ArraySizeHelper(T (&array)[N]))[N];
#define arraysize(array) (sizeof(ArraySizeHelper(array)))

C++11版本 :
template<typename T, size_t N>
auto ArraySizeHelper(T (&array)[N]) -> char(&)[N];


The function template is named ArraySizeHelper, for a function that takes one argument, a reference to a T [N], and returns a reference to a char [N].

The macro passes your object (let's say it's X obj[M]) as the argument. The compiler infers that T == X and N == M. So it declares a function with a return type of char (&)[M]. The macro then wraps this return value with sizeof, so it's really doing sizeof(char [M]), which is M.

If you give it a non-array type (e.g. a T *), then the template parameter inference will fail.

As @Alf points out below, the advantage of this hybrid template-macro system over the alternative template-only approach is that this gives you a compile-time constant.