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


Groups > comp.lang.c > #75870

Re: Funny C Program

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Funny C Program
Date 2015-11-12 11:59 -0800
Organization None to speak of
Message-ID <ln37wbq98h.fsf@kst-u.example.com> (permalink)
References (5 earlier) <563E25B0.8080504@verizon.net> <68f7c46c-0248-4dcd-8073-46a938d5e427@googlegroups.com> <563E9DA5.70603@verizon.net> <563F7132.4010804@verizon.net> <n22lpe$749$1@dont-email.me>

Show all headers | View raw


James Kuyper <jameskuyper@verizon.net> writes:
> On 11/08/2015 10:58 AM, James Kuyper wrote:
[...]
>>> Unless I'm missing something (which is unfortunately entirely possible),
>>> the only possible problem with your code is that it doesn't terminate
>>> the output with a new-line character (7.21.2p2), but it's unusual for
>>> anything to go wrong for that reason, and quite bizarre that it would go
>>> wrong in this fashion.
>> 
>> In case you're unwilling to trust a link to an unknown web page, here's
>> the relevant details from the page it refers to. jimzhou001 passed the
>> following code to C4droid:
>> 
>>     include <stdio.h>
>>     int main(void)
>>     {
>>         int i,array[101]={0};
>>         for(i=1;i<101;i++)
>>             printf(" %d",array[i]);
>>         return 0;
>>     }
>> 
>> (I added some white space not present in the original program, to aid
>> readability)
>> 
>> As I understand it, the output from that program should consist of 100
>> repeats of " 0". jimzhou001 reports the output from that program using a
>> screen shot, so I can't cut and paste it here, but the output contains
>> 100 numbers, each preceded by a single space, with the first 60 numbers
>> and last 4 numbers all 0. There's a long string of non-zero values
>> starting at the 61st position with "1 -1092757696 -1092757628 78752 19 ...".
>> 
>> Can you confirm and explain the behavior of this program when compiled
>> by C4droid?
>
> I got a response from Roman Lebedev (n0n3m4@gmail.com). Since he did not
> give me explicit permission to repost his response, I won't, but he
> didn't say anything particularly private. He basically passed
> responsibility for this problem over to the TCC compiler used by
> C4droid. He said nothing to suggest that he'd performed any kind of
> detailed investigation to find out what was going wrong.
>
> Does anyone have a copy of TCC that is not part of C4droid, that they
> can test this code with? If so, and if you can duplicate the problem, I
> suppose a bug report can be passed on to the people responsible for TCC.

I just compiled and ran that program using tcc version 0.9.25 on Linux
Mint 17.2, x86_64.  It produced the correct output, 100 occurrences of
" 0".

It could still be a bug that depends on the target system, on the
compiler version, or just on bad luck (if the {0} initializer doesn't
work correctly, the contents of `array` might or might not be all zeros
just by chance).  I don't see an option to generate an assembly listing,
but by fiddling around with a few things it does seem likely that the
compiler is generating code to zero the array.

-- 
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"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Funny C Program jimzhou001@gmail.com - 2015-11-03 17:54 -0800
  Re: Funny C Program bartekltg <bartekltg@gmail.com> - 2015-11-04 05:28 +0100
    Re: Funny C Program Richard Heathfield <rjh@cpax.org.uk> - 2015-11-04 07:12 +0000
      Re: Funny C Program bartekltg <bartekltg@gmail.com> - 2015-11-04 13:25 +0100
        Re: Funny C Program bartekltg <bartekltg@gmail.com> - 2015-11-04 13:52 +0100
          Re: Funny C Program jimzhou001@gmail.com - 2015-11-04 06:36 -0800
    Re: Funny C Program jimzhou001@gmail.com - 2015-11-04 02:28 -0800
      Re: Funny C Program bartekltg <bartekltg@gmail.com> - 2015-11-04 13:25 +0100
    Re: Funny C Program Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-04 19:07 -0800
      Re: Funny C Program bartekltg <bartekltg@gmail.com> - 2015-11-05 09:48 +0100
        Re: Funny C Program Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-05 06:08 -0800
  Re: Funny C Program Richard Heathfield <rjh@cpax.org.uk> - 2015-11-04 07:04 +0000
    Re: Funny C Program jimzhou001@gmail.com - 2015-11-04 02:33 -0800
      Re: Funny C Program Richard Heathfield <rjh@cpax.org.uk> - 2015-11-04 10:57 +0000
        Re: Funny C Program jimzhou001@gmail.com - 2015-11-04 03:46 -0800
          Re: Funny C Program luser droog <luser.droog@gmail.com> - 2015-11-04 10:46 -0800
            Re: Funny C Program jimzhou001@gmail.com - 2015-11-04 15:14 -0800
  Re: Funny C Program brian.oakley@stonybrook.edu - 2015-11-04 12:37 -0800
    Re: Funny C Program jimzhou001@gmail.com - 2015-11-04 15:30 -0800
  Funny C Program jimzhou001@gmail.com - 2015-11-06 16:40 -0800
    Re: Funny C Program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-07 01:04 +0000
      Re: Funny C Program Keith Thompson <kst-u@mib.org> - 2015-11-06 17:12 -0800
        Re: Funny C Program jimzhou001@gmail.com - 2015-11-06 18:47 -0800
          Re: Funny C Program James Kuyper <jameskuyper@verizon.net> - 2015-11-07 11:24 -0500
            Re: Funny C Program jimzhou001@gmail.com - 2015-11-07 16:21 -0800
              Re: Funny C Program Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-08 00:46 +0000
              Re: Funny C Program James Kuyper <jameskuyper@verizon.net> - 2015-11-07 19:56 -0500
                Re: Funny C Program jimzhou001@gmail.com - 2015-11-07 19:08 -0800
                Re: Funny C Program James Kuyper <jameskuyper@verizon.net> - 2015-11-08 10:58 -0500
                Re: Funny C Program James Kuyper <jameskuyper@verizon.net> - 2015-11-12 13:31 -0500
                Re: Funny C Program Keith Thompson <kst-u@mib.org> - 2015-11-12 11:59 -0800
                Re: Funny C Program jimzhou001@gmail.com - 2015-11-17 23:00 -0800
                Re: Funny C Program jimzhou001@gmail.com - 2015-11-18 00:12 -0800
                Re: Funny C Program Keith Thompson <kst-u@mib.org> - 2015-11-18 09:01 -0800
                Re: Funny C Program jimzhou001@gmail.com - 2015-11-17 23:00 -0800
    Re: Funny C Program James Kuyper <jameskuyper@verizon.net> - 2015-11-06 20:07 -0500

csiph-web