Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c.moderated > #471

Re: Why sizeof(main) = 1?

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c.moderated
Subject Re: Why sizeof(main) = 1?
Date 2013-09-11 17:26 -0500
Organization None to speak of
Message-ID <clcm-20130911-0002@plethora.net> (permalink)
References <clcm-20130104-0002@plethora.net> <clcm-20130902-0002@plethora.net> <clcm-20130906-0002@plethora.net>

Show all headers | View raw


James Kuyper <jameskuyper@verizon.net> writes:
> On 09/02/2013 05:07 AM, kzelechowski@e3tech.local wrote:
>> (sizeof main == 1) because (main) is treated as a logical value.  Compare: 
>> { if (main) yadda; }
>
> Why are you resurrecting a thread that started eight months ago, and was
> completely resolved six months ago?
>
> The behavior of an if() statement depends upon whether the if-condition
> compares equal to 0. You could think of if(main) as if it evaluates
> main==0, though that's not how the C standard describes it.

Or you could think of it as if it evaluates main!=0 -- which very nearly
is how the C standard describes it:

    In both forms [of the "if" statement], the first substatement is
    executed if the expression compares unequal to 0

Since the expression main decays to a pointer, the 0 is treated as a
null pointer constant and is converted to the same pointer type.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
-- 
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.

Back to comp.lang.c.moderated | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Why sizeof(main) = 1? Myth__Buster <raghavanil4m@gmail.com> - 2013-01-04 18:14 -0600
  Re: Why sizeof(main) = 1? Barry Schwarz <schwarzb@dqel.com> - 2013-02-26 10:51 -0600
    Re: Why sizeof(main) = 1? Keith Thompson <kst-u@mib.org> - 2013-03-11 18:25 -0500
  Re: Why sizeof(main) = 1? Jasen Betts <jasen@xnet.co.nz> - 2013-02-26 10:51 -0600
  Re: Why sizeof(main) = 1? gordonb.k8xjg@burditt.org (Gordon Burditt) - 2013-02-26 10:51 -0600
  Re: Why sizeof(main) = 1? <kzelechowski@e3tech.local> - 2013-09-02 04:07 -0500
    Re: Why sizeof(main) = 1? James Kuyper <jameskuyper@verizon.net> - 2013-09-06 23:25 -0500
      Re: Why sizeof(main) = 1? Keith Thompson <kst-u@mib.org> - 2013-09-11 17:26 -0500
        Re: Why sizeof(main) = 1? James Kuyper <jameskuyper@verizon.net> - 2013-09-12 11:29 -0500
    Re: Why sizeof(main) = 1? Keith Thompson <kst-u@mib.org> - 2013-09-06 23:25 -0500
      Re: Why sizeof(main) = 1? Robert Wessel <robertwessel2@yahoo.com> - 2013-09-11 17:27 -0500
        Re: Why sizeof(main) = 1? James Kuyper <jameskuyper@verizon.net> - 2013-09-12 11:29 -0500
        Re: Why sizeof(main) = 1? Keith Thompson <kst-u@mib.org> - 2013-09-12 11:30 -0500
    Re: Why sizeof(main) = 1? Ken Brody <kenbrody@spamcop.net> - 2013-09-06 23:25 -0500

csiph-web