Groups | Search | Server Info | Login | Register


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

Re: Why sizeof(main) = 1?

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c.moderated
Subject Re: Why sizeof(main) = 1?
Date 2013-09-12 11:29 -0500
Organization A noiseless patient Spider
Message-ID <clcm-20130912-0001@plethora.net> (permalink)
References <clcm-20130104-0002@plethora.net> <clcm-20130902-0002@plethora.net> <clcm-20130906-0002@plethora.net> <clcm-20130911-0002@plethora.net>

Show all headers | View raw


On 09/11/2013 06:26 PM, Keith Thompson wrote:
> 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.

My key point was that the description of the semantics of an if()
statement are not related to the rules governing the type of the result
of a comparison expression (whether it's an equality or inequality
expression is irrelevant to my point). Thus, connecting the value of
"sizeof main" to the semantics of if(main) is meaningless (and not just
for this reason - my full message gave other, more important reasons).
-- 
James Kuyper
-- 
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