This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: sizeof(function)
- To: Horst von Brand <vonbrand at inf dot utfsm dot cl>
- Subject: Re: sizeof(function)
- From: Geoff Keating <geoffk at cygnus dot com>
- Date: 16 Jun 2000 13:49:02 -0700
- CC: gcc-bugs at gcc dot gnu dot org
- References: <200006161937.e5GJbgL20024@pincoya.inf.utfsm.cl>
Horst von Brand <vonbrand@inf.utfsm.cl> writes:
> Andi Kleen <ak@muc.de> said:
> > The following program outputs 1:
> >
> > main()
> > {
> > printf("%d\n",sizeof(main));
> > }
> >
> > Why does it not give an error ? The c9x draft does not seem to define
> > this case, but surely it should at least warn about this.
>
> Whenever you mention a function without calling it, you get a pointer to
> the function, isn't it? 1 is wrong in any case.
It does give a warning if you use -pedantic. Functions don't decay to
pointers in the context of sizeof(), just as arrays don't.
--
- Geoffrey Keating <geoffk@cygnus.com>