public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Mihai Donțu" <mihai.dontu@gmail.com>
To: Brian Dessent <brian@dessent.net>
Cc: gcc-help@gcc.gnu.org
Subject: Re: sizeof( function )
Date: Tue, 12 Jun 2007 17:05:00 -0000	[thread overview]
Message-ID: <200706121938.26865.mihai.dontu@gmail.com> (raw)
In-Reply-To: <466EC9C6.A5DF578A@dessent.net>

On Tuesday 12 June 2007 19:28, Brian Dessent wrote:
> Mihai Don?u wrote:
> 
> > Not that is of great importance, but does anyone know why
> > 
> > int main( void )
> > {
> >         return printf( "%d\n", ( int )sizeof( main ) );
> > }
> > 
> > prints 1 ? :)
> > 
> > (sizeof( &main ) prints 4/8 as it should)
> 
> In this context 'main' is a function type, i.e. a type that describes a
> function of a given return type and a given number and type of arguments
> (C99 §6.2.5 para. 20).  It is invalid to use sizeof() with a function
> type expression (C99 §6.5.3.4 para. 1) and hence this code invokes
> undefined behavior.  gcc gives a warning if you compile with -pedantic,
> but otherwise it apparently just returns 1; it would be equally within
> its rights to return 42 or to generate code to format the users hard
> drive -- that is the nature of undefined behavior.

  Unlike me, you really do know your C99 book :)

  Thanks a lot!

-- 
Mihai Donțu

  parent reply	other threads:[~2007-06-12 16:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-12 16:12 Mihai Donțu
2007-06-12 16:38 ` Brian Dessent
2007-06-12 16:56   ` Segher Boessenkool
2007-06-12 17:05   ` Mihai Donțu [this message]
2007-06-12 17:57   ` Ian Lance Taylor
2007-06-14 12:44   ` Martin Krischik
2007-06-12 17:18 Nick Maclaren
2007-06-12 17:27 ` Brian Dessent
2007-06-12 17:47 ` Segher Boessenkool
2007-06-12 21:55 Nick Maclaren
2007-06-14 13:14 Nick Maclaren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200706121938.26865.mihai.dontu@gmail.com \
    --to=mihai.dontu@gmail.com \
    --cc=brian@dessent.net \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).