[Box Backup-dev] COMMIT r255 - in box/chris/win32/vc2005-compile-fixes/lib: common compress server win32

Martin Ebourne boxbackup-dev@fluffy.co.uk
Wed, 21 Dec 2005 09:07:09 +0000


Stupid email program sent the email when I accidentally held ctrl and
pressed enter!

On Wed, 2005-12-21 at 01:41 +0000, Chris Wilson wrote:
> Hi Martin,
> 
> > Please don't use a platform check for header files. Please add a
> > configure test (AC_CHECK_HEADERS) and use its define.
> 
> How would I check the type of struct timeval.tv_sec using autoconf?

Firstly use a run block to run some test code. There's already an
example in configure.ac:

AC_CACHE_CHECK([if we have large file support enabled], [have_large_file_support],
  [AC_RUN_IFELSE([AC_LANG_PROGRAM([[$ac_includes_default]], [[
      return sizeof(off_t)==4;
    ]])],
    [have_large_file_support=yes], [have_large_file_support=no]
  )])
if test "x$have_large_file_support" = "xyes"; then
  AC_DEFINE([HAVE_LARGE_FILE_SUPPORT], 1, [Define to 1 large file support is in use])
fi

Now the fun comes in trying to detect at run time what the type is. I
can think of several possibilities:

1. Use sizeof. Of course, this only works if the sizes are known and
vary.

2. Cast the member using say a const_cast. Thus if the type does not
match the program will fail to compile. In this case you could use the
compile variant of RUN_IFELSE.

3. Use overloading. Write 2 or more functions 'foo' that take a
parameter of different types and return an int with different values.
Then call it and the compiler will tell you which type you have. May not
work because you may not know all the types.

4. Use template partial specialisation. Write a template function 'foo'
that is just like the foo in (3) but is type generic. Get it to return 0
say. Then write a specialisation for it with the type you want to match,
and make that return 1. Much like (3) but should always work - this is
the most generic method.

One of those should sort you out. Unfortunately of the obvious two
candidates, typeof is a g++ extension and C++ rtti only works on
polymorphic classes.

Cheers,

Martin.