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


Groups > comp.lang.c > #9730 > unrolled thread

I think this is an impossible assignment...could you help?

Started byJack <spamtrap@trashcan.invalid>
First post2011-08-30 21:01 +0000
Last post2011-09-02 08:32 -0700
Articles 7 on this page of 67 — 20 participants

Back to article view | Back to comp.lang.c


Contents

  I think this is an impossible assignment...could you help? Jack <spamtrap@trashcan.invalid> - 2011-08-30 21:01 +0000
    Re: I think this is an impossible assignment...could you help? Ian Collins <ian-news@hotmail.com> - 2011-08-31 09:18 +1200
      Re: I think this is an impossible assignment...could you help? Jack <spamtrap@trashcan.invalid> - 2011-08-30 21:20 +0000
        Re: I think this is an impossible assignment...could you help? Ian Collins <ian-news@hotmail.com> - 2011-08-31 10:34 +1200
    Re: I think this is an impossible assignment...could you help? John Gordon <gordon@panix.com> - 2011-08-30 21:29 +0000
      Re: I think this is an impossible assignment...could you help? Jack <spamtrap@trashcan.invalid> - 2011-08-30 21:43 +0000
        Re: I think this is an impossible assignment...could you help? John Gordon <gordon@panix.com> - 2011-08-30 22:16 +0000
          Re: I think this is an impossible assignment...could you help? William Ahern <william@wilbur.25thandClement.com> - 2011-08-30 16:26 -0700
          Re: I think this is an impossible assignment...could you help? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-30 21:44 -0400
            Re: I think this is an impossible assignment...could you help? John Gordon <gordon@panix.com> - 2011-08-31 02:03 +0000
              Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-08-31 08:56 -0700
                Re: I think this is an impossible assignment...could you help? John Gordon <gordon@panix.com> - 2011-08-31 16:15 +0000
                  Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-08-31 09:20 -0700
                  Re: I think this is an impossible assignment...could you help? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-31 21:15 -0400
                    Re: I think this is an impossible assignment...could you help? James Kuyper <jameskuyper@verizon.net> - 2011-08-31 22:18 -0400
                    Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-01 15:06 +0000
                  Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-01 15:04 +0000
                    Re: I think this is an impossible assignment...could you help? John Gordon <gordon@panix.com> - 2011-09-01 15:20 +0000
                    Re: I think this is an impossible assignment...could you help? David Thompson <dave.thompson2@verizon.net> - 2011-09-06 01:20 -0400
        Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-08-30 16:37 -0700
        Re: I think this is an impossible assignment...could you help? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-31 00:51 +0100
          Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-08-31 13:28 +0000
            Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-01 15:03 +0000
              Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-01 08:49 -0700
                Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-02 07:46 +0000
              Re: I think this is an impossible assignment...could you help? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-01 21:30 -0400
                Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-02 07:48 +0000
        Re: I think this is an impossible assignment...could you help? Ian Collins <ian-news@hotmail.com> - 2011-08-31 11:58 +1200
        Re: I think this is an impossible assignment...could you help? Ike Naar <ike@sverige.freeshell.org> - 2011-08-31 07:27 +0000
    Re: I think this is an impossible assignment...could you help? "BartC" <bc@freeuk.com> - 2011-08-31 10:37 +0100
      Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-08-31 13:29 +0000
        Re: I think this is an impossible assignment...could you help? "BartC" <bc@freeuk.com> - 2011-08-31 18:41 +0100
          Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-01 15:05 +0000
        Re: I think this is an impossible assignment...could you help? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-09-02 01:42 -0700
      Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-08-31 09:15 -0700
        Re: I think this is an impossible assignment...could you help? "BartC" <bc@freeuk.com> - 2011-08-31 18:36 +0100
          Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-08-31 11:44 -0700
        Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-01 15:05 +0000
          Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-01 08:51 -0700
            Re: I think this is an impossible assignment...could you help? "BartC" <bc@freeuk.com> - 2011-09-01 17:26 +0100
              Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-02 07:47 +0000
                Re: I think this is an impossible assignment...could you help? "BartC" <bc@freeuk.com> - 2011-09-02 10:56 +0100
                  Re: I think this is an impossible assignment...could you help? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-09-05 20:21 +0000
                    Re: I think this is an impossible assignment...could you help? "Bartc" <bc@freeuk.com> - 2011-09-09 13:59 +0100
      Re: I think this is an impossible assignment...could you help? "BartC" <bc@freeuk.com> - 2011-09-02 10:43 +0100
    Re: I think this is an impossible assignment...could you help? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-09-01 12:02 -0600
      Re: I think this is an impossible assignment...could you help? James Kuyper <jameskuyper@verizon.net> - 2011-09-01 15:12 -0400
        Re: I think this is an impossible assignment...could you help? sandeep <nospam@nospam.com> - 2011-09-01 19:36 +0000
        Re: I think this is an impossible assignment...could you help? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-09-01 14:53 -0600
          Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-01 16:01 -0700
            Re: I think this is an impossible assignment...could you help? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-09-01 17:22 -0600
              Re: I think this is an impossible assignment...could you help? pete <pfiland@mindspring.com> - 2011-09-01 19:39 -0400
              Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-01 16:39 -0700
                Re: I think this is an impossible assignment...could you help? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-09-01 18:51 -0600
                  Re: I think this is an impossible assignment...could you help? pete <pfiland@mindspring.com> - 2011-09-01 22:27 -0400
                  Re: I think this is an impossible assignment...could you help? James Kuyper <jameskuyper@verizon.net> - 2011-09-01 22:53 -0400
                  Re: I think this is an impossible assignment...could you help? Kenneth Brody <kenbrody@spamcop.net> - 2011-09-02 10:45 -0400
                    Re: I think this is an impossible assignment...could you help? James Kuyper <jameskuyper@verizon.net> - 2011-09-02 11:02 -0400
                  Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-02 08:05 -0700
                    Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-02 08:17 -0700
                    Re: I think this is an impossible assignment...could you help? Willem <willem@toad.stack.nl> - 2011-09-02 15:18 +0000
                      Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-02 08:42 -0700
              Re: I think this is an impossible assignment...could you help? James Kuyper <jameskuyper@verizon.net> - 2011-09-01 23:21 -0400
            Re: I think this is an impossible assignment...could you help? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-01 21:53 -0400
              Re: I think this is an impossible assignment...could you help? James Kuyper <jameskuyper@verizon.net> - 2011-09-01 23:09 -0400
      Re: I think this is an impossible assignment...could you help? Michael Press <rubrum@pacbell.net> - 2011-09-01 21:43 -0700
      Re: I think this is an impossible assignment...could you help? Keith Thompson <kst-u@mib.org> - 2011-09-02 08:32 -0700

Page 4 of 4 — ← Prev page 1 2 3 [4]


#9892

FromWillem <willem@toad.stack.nl>
Date2011-09-02 15:18 +0000
Message-ID<slrnj61stn.1od7.willem@toad.stack.nl>
In reply to#9889
Keith Thompson wrote:
) Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
)> Well, sure, but by that definition his assignment really is impossible,
)> since it calls for him to get input from stdin.

I just reread the OP.
It calls for him to get input from 'the standard input stream'.

) I think we can assume that he's allowed to call fgetc(), or fgets(),
) or something similar.

No, he's not allowed to do that.
According to the assignment, he has to use getchar().


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

[toc] | [prev] | [next] | [standalone]


#9895

FromKeith Thompson <kst-u@mib.org>
Date2011-09-02 08:42 -0700
Message-ID<lnk49rq7c8.fsf@nuthaus.mib.org>
In reply to#9892
Willem <willem@toad.stack.nl> writes:
> Keith Thompson wrote:
> ) Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
> )> Well, sure, but by that definition his assignment really is impossible,
> )> since it calls for him to get input from stdin.
>
> I just reread the OP.
> It calls for him to get input from 'the standard input stream'.
>
> ) I think we can assume that he's allowed to call fgetc(), or fgets(),
> ) or something similar.
>
> No, he's not allowed to do that.
> According to the assignment, he has to use getchar().

Which would be "something similar".

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#9866

FromJames Kuyper <jameskuyper@verizon.net>
Date2011-09-01 23:21 -0400
Message-ID<j3pi39$asc$1@dont-email.me>
In reply to#9844
On 09/01/2011 07:22 PM, Joe Pfeiffer wrote:
> Keith Thompson <kst-u@mib.org> writes:
> 
>> Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
>>> James Kuyper <jameskuyper@verizon.net> writes:
>> [...]
>>>> scanf() doesn't happen to be one of those functions; the required
>>>> behavior for scanf() can be implemented entirely in C code that calls
>>>> other C standard library functions, without using any of the other
>>>> members of the scanf() family. But if your argument were valid, it would
>>>> also apply to fgetc().
>>>
>>> Actually, I was unaware that fgetc() had any non-C code in it -- what
>>> does it do that requires assembler?
>>
>> fgetc() cannot be written in *portable* C.
> 
> What in it requires non-portable C?

Can you provide a portable version?

There's no C language construct that has, as it's standard-defined
semantics, the retrieval of a byte of data from an external device. Any
code you write that has that effect must necessarily be relying upon
something implementation-specific.

Are you thinking of implementing fgetc() by calling some other C
standard library functions? For example:

	int fgetc(FILE *stream)
	{
	    char c;
	    if(fread(&c, 1, 1, stream) != 1)
	       return EOF;
	    else
	       return c;
	}

The problem with that approach is that fread() is defined as calling
fgetc(), which would cause infinite recursion. Because of the as-if
rule, fread() doesn't have to actually call fgetc(), but it does at
least have to produce the same effects as if it actually had called
fgetc(). All you've done is pass the issue on to fread(). Sooner or
later, somewhere along the way, there has to be a function that is part
of, or called by C standard library functions, which actually reads one
or more bytes of data from a data storage device without calling any
other functions (except possibly OS-specific functions). So how do you
do that in portable C (which cannot call OS-specific functions)?

The same is true of any other C standard library function that reads one
or more bytes of input from a stream - they all ultimately trace their
required behavior back to fgetc().
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#9859

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2011-09-01 21:53 -0400
Message-ID<j3pcu4$grd$1@dont-email.me>
In reply to#9842
On 9/1/2011 7:01 PM, Keith Thompson wrote:
>[...]
> fgetc() cannot be written in *portable* C.

	#include <stdio.h>
	int fgetc(FILE *stream) {
	    return getc(stream);
	}

     You may object that this isn't "portable" because it relies on
the knowledge that getc() doesn't call fgetc(), knowledge that the
implementation has but a portable user program lacks.  But then, no
portable user program can implement fgetc() at all, nor strlen() nor
sqrt() nor anything else in the Standard library: They all belong to
the implementation, so any attempt to implement them in portable C
is doomed from the word "Go."

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

[toc] | [prev] | [next] | [standalone]


#9865

FromJames Kuyper <jameskuyper@verizon.net>
Date2011-09-01 23:09 -0400
Message-ID<j3phdl$7rg$1@dont-email.me>
In reply to#9859
On 09/01/2011 09:53 PM, Eric Sosman wrote:
> On 9/1/2011 7:01 PM, Keith Thompson wrote:
>> [...]
>> fgetc() cannot be written in *portable* C.
> 
> 	#include <stdio.h>
> 	int fgetc(FILE *stream) {
> 	    return getc(stream);
> 	}
> 
>      You may object that this isn't "portable" because it relies on
> the knowledge that getc() doesn't call fgetc(), knowledge that the
> implementation has but a portable user program lacks.

No, the real problem is that it just pushes the issue off to getc().
Whether fgetc() calls getc(), or vice versa, one of them actually has to
read a character from a storage device, and that's where the real
problem comes in.

>  But then, no
> portable user program can implement fgetc() at all, nor strlen() nor
> sqrt() nor anything else in the Standard library: They all belong to
> the implementation, so any attempt to implement them in portable C
> is doomed from the word "Go."

The rules for reserved identifiers impose different restrictions on user
code than they do on standard library code. It is otherwise no problem
at all writing portable C code to implement things like strlen():

	size_t strlen(const char *s)
	{
	    size_t retval=0;
	    while(*s++)
		retval++;
	    return retval;
	}

Can you show me comparable code for an implementation of getc() that is
compatible with your fgetc() implementation above? Compatibility means
that, among other things, it can't call fgetc(). If it calls some other
standard library function to perform the read which fills the buffer,
then I'd like to see the implementation of that function too. Repeat
until you've shown the portable code which implements the actual read
itself. I'd really like to see what that looks like.
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#9869

FromMichael Press <rubrum@pacbell.net>
Date2011-09-01 21:43 -0700
Message-ID<rubrum-D6FA3E.21431001092011@news.albasani.net>
In reply to#9829
In article <1br540b0oo.fsf@snowball.wb.pfeifferfamily.net>,
 Joe Pfeiffer <pfeiffer@cs.nmsu.edu> wrote:

> "Erwin, have you seen the cat?" -- Mrs. Shroedinger

--Maybe.

-- 
Michael Press

[toc] | [prev] | [next] | [standalone]


#9893

FromKeith Thompson <kst-u@mib.org>
Date2011-09-02 08:32 -0700
Message-ID<lnobz3q7rw.fsf@nuthaus.mib.org>
In reply to#9829
Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
> --
> "Erwin, have you seen the cat?" -- Mrs. Shroedinger

Yes and no.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [standalone]


Page 4 of 4 — ← Prev page 1 2 3 [4]

Back to top | Article view | comp.lang.c


csiph-web