Web lists-archives.com

Re: ssize_t




On 12/22/2016 02:14 PM, Eric Blake wrote:

>> ssize_t.c:115:22: error: expected expression before ‘)’ token
>>  if (sizeof ((ssize_t)))
>>                       ^

> That's probably SUPPOSED to happen.
> 
> Autoconf tests for type names by comparing:

In fact, read the autoconf source code:

http://git.sv.gnu.org/cgit/autoconf.git/tree/lib/autoconf/types.m4#n56


# _AC_CHECK_TYPE_NEW_BODY
# -----------------------
# Shell function body for _AC_CHECK_TYPE_NEW.  This macro implements the
# former task of AC_CHECK_TYPE, with one big difference though:
AC_CHECK_TYPE
# used to grep in the headers, which, BTW, led to many problems until the
# extended regular expression was correct and did not give false positives.
# It turned out there are even portability issues with egrep...
#
# The most obvious way to check for a TYPE is just to compile a variable
# definition:
#
#	  TYPE my_var;
#
# (TYPE being the second parameter to the shell function, hence $[]2 in m4).
# Unfortunately this does not work for const qualified types in C++, where
# you need an initializer.  So you think of
#
#	  TYPE my_var = (TYPE) 0;
#
# Unfortunately, again, this is not valid for some C++ classes.
#
# Then you look for another scheme.  For instance you think of declaring
# a function which uses a parameter of type TYPE:
#
#	  int foo (TYPE param);
#
# but of course you soon realize this does not make it with K&R
# compilers.  And by no means do you want to use this:
#
#	  int foo (param)
#	    TYPE param
#	  { ; }
#
# since C++ would complain loudly.
#
# Don't even think of using a function return type, since K&R cries
# there too.  So you start thinking of declaring a *pointer* to this TYPE:
#
#	  TYPE *p;
#
# but you know fairly well that this is legal in C for aggregates which
# are unknown (TYPE = struct does-not-exist).
#
# Then you think of using sizeof to make sure the TYPE is really
# defined:
#
#	  sizeof (TYPE);
#
# That is great, but has one drawback: it succeeds when TYPE happens
# to be a variable: you'd get the size of the variable's type.
# Obviously, we must not accept a variable in place of a type name.
#
# So, to filter out the last possibility, we will require that this fail:
#
#	  sizeof ((TYPE));
#
# This evokes a syntax error when TYPE is a type, but succeeds if TYPE
# is actually a variable.
#
# Also note that we use
#
#	  if (sizeof (TYPE))
#
# to `read' sizeof (to avoid warnings), while not depending on its type
# (not necessarily size_t etc.).
#
# C++ disallows defining types inside `sizeof ()', but that's OK,
# since we don't want to consider unnamed structs to be types for C++,
# precisely because they don't work in cases like that.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature