Use of typeof
Philip Cheng
cheng@PCIgeomatics.com
Mon Mar 4 06:36:00 GMT 2002
Kevin:
If you look at
http://gcc.gnu.org/onlinedocs/gcc-3.0.3/gcc_5.html#SEC74
you will find that typeof is gcc extension.
There are two ways of writing the argument to typeof: with an expression
or with a type. Here is an example with an expression:
typeof (x[0](1))
This assumes that x is an array of pointers to functions; the type described
is that of the values of the functions.
Here is an example with a typename as the argument:
typeof (int *)
Seems typeof does not work with the 2nd method. Maybe it is a gcc bug?
Philip
>
> There is no such thing as typeof in C.
>
> However, there is in C++ so either rename your file to test.cc
> or compile with -xc++.
>
> On Fri, Mar 01, 2002 at 11:01:18AM -0500, Philip Cheng wrote:
> > I would like to use typeof to determine the type of a variable.
> > However, I keep getting the error when I try to compile the program.
> >
> > test.c: In function `main':
> > test.c:8: parse error before "typeof"
> >
> > Anyone knows how can I solve the problem? Thanks in advance for your help.
> >
> > Philip
> >
> >
> > Here is my test program:
> >
> > #include <stdio.h>
> >
> > main()
> > {
> > double dftest;
> > dftest = 1.0;
> >
> > if (__builtin_types_compatible_p (typeof (dftest), double))
> > printf("It is double\n");
> > }
>
More information about the Gcc-help
mailing list