public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Use of typeof
@ 2002-03-01  8:03 Philip Cheng
  2002-03-02 11:04 ` Kevin Bailey
  0 siblings, 1 reply; 4+ messages in thread
From: Philip Cheng @ 2002-03-01  8:03 UTC (permalink / raw)
  To: gcc-help

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");
} 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Use of typeof
  2002-03-01  8:03 Use of typeof Philip Cheng
@ 2002-03-02 11:04 ` Kevin Bailey
  2002-03-02 13:43   ` Kevin Bailey
  2002-03-04  6:36   ` Philip Cheng
  0 siblings, 2 replies; 4+ messages in thread
From: Kevin Bailey @ 2002-03-02 11:04 UTC (permalink / raw)
  To: gcc-help

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");
> } 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Use of typeof
  2002-03-02 11:04 ` Kevin Bailey
@ 2002-03-02 13:43   ` Kevin Bailey
  2002-03-04  6:36   ` Philip Cheng
  1 sibling, 0 replies; 4+ messages in thread
From: Kevin Bailey @ 2002-03-02 13:43 UTC (permalink / raw)
  To: gcc-help

Oops, it's typeid, not typeof.

On Sat, Mar 02, 2002 at 11:04:14AM -0800, Kevin Bailey wrote:
> 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++.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Use of typeof
  2002-03-02 11:04 ` Kevin Bailey
  2002-03-02 13:43   ` Kevin Bailey
@ 2002-03-04  6:36   ` Philip Cheng
  1 sibling, 0 replies; 4+ messages in thread
From: Philip Cheng @ 2002-03-04  6:36 UTC (permalink / raw)
  To: Kevin Bailey; +Cc: gcc-help

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");
> > } 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-03-04 14:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-01  8:03 Use of typeof Philip Cheng
2002-03-02 11:04 ` Kevin Bailey
2002-03-02 13:43   ` Kevin Bailey
2002-03-04  6:36   ` Philip Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).