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 20 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 3 of 4 — ← Prev page 1 2 [3] 4  Next page →


#9875

Fromblmblm@myrealbox.com <blmblm.myrealbox@gmail.com>
Date2011-09-02 07:47 +0000
Message-ID<9cbg1aFftvU2@mid.individual.net>
In reply to#9826
In article <j3obqu$l0f$1@dont-email.me>, BartC <bc@freeuk.com> wrote:
> "Keith Thompson" <kst-u@mib.org> wrote in message 
> news:lnfwkgs1k0.fsf@nuthaus.mib.org...
> > blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> writes:
> >> In article <lnmxeptv4b.fsf@nuthaus.mib.org>,
> >> Keith Thompson  <kst-u@mib.org> wrote:
> 
> >>>     #define INVALID LONG_MIN
> 
> >> And then you disallow one legitimate input ....  Well, I guess
> >> the options for signalling errors are limited.  <shrug>?
> >
> > So I can't enter -2147483648.  Oh, darn.  8-)}
> >
> > In real life, checking for end-of-file would make a lot more sense, but
> > this is a beginner's assignment.
> 
> I think he meant the -999 that is used to stop the program...

I'm not sure who "he" is in this sentence (and for once I'm not just
making my usual quibble about the gender of the pronoun).  

I'll agree that using some particular value to mean "no more input"
doesn't seem as satisfactory as just using end of file, though it's
not unusual in a beginning program and maybe not even very bad in
that context.

But my comment about disallowing one legitimate input was in
reference to signalling *errors* using something that could be
a legitimate return value -- that does seem less than optimal,
though it's not clear how one could do better without changing the
function signature.

> (If it was my specification, I might have just used an empty line to end. 
> However this is after all just an exercise.)

-- 
B. L. Massingill
ObDisclaimer:  I don't speak for my employers; they return the favor.

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


#9879

From"BartC" <bc@freeuk.com>
Date2011-09-02 10:56 +0100
Message-ID<j3q9cb$um8$2@dont-email.me>
In reply to#9875

"blmblm@myrealbox.com" <blmblm.myrealbox@gmail.com> wrote in message 
news:9cbg1aFftvU2@mid.individual.net...
> In article <j3obqu$l0f$1@dont-email.me>, BartC <bc@freeuk.com> wrote:
>> "Keith Thompson" <kst-u@mib.org> wrote in message
>> news:lnfwkgs1k0.fsf@nuthaus.mib.org...
>> > blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> writes:

>> >> And then you disallow one legitimate input ....  Well, I guess

>> > So I can't enter -2147483648.  Oh, darn.  8-)}

>> I think he meant the -999 that is used to stop the program...
>
> I'm not sure who "he" is in this sentence (and for once I'm not just
> making my usual quibble about the gender of the pronoun).

It seems I interpreted your "And then" in the wrong way.

As for "he", that did mean you, but in the absence of clear evidence 
otherwise, it's often taken to mean "he" or "she". Especially around here..

> I'll agree that using some particular value to mean "no more input"
> doesn't seem as satisfactory as just using end of file, though it's
> not unusual in a beginning program and maybe not even very bad in
> that context.

Yes, at least the user knows that -999 is not an input, but doesn't know 
that -2147483648 isn't (and nor are most integers for that matter which 
aren't in the narrow range of LONG_MIN(+1) to LONG_MAX.) But proper range 
checking would be far too difficult for a beginner's exercise.

-- 
Bartc 

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


#9955

Fromblmblm@myrealbox.com <blmblm.myrealbox@gmail.com>
Date2011-09-05 20:21 +0000
Message-ID<9ckpavFv7eU1@mid.individual.net>
In reply to#9879
In article <j3q9cb$um8$2@dont-email.me>, BartC <bc@freeuk.com> wrote:
> 
> 
> "blmblm@myrealbox.com" <blmblm.myrealbox@gmail.com> wrote in message 
> news:9cbg1aFftvU2@mid.individual.net...
> > In article <j3obqu$l0f$1@dont-email.me>, BartC <bc@freeuk.com> wrote:
> >> "Keith Thompson" <kst-u@mib.org> wrote in message
> >> news:lnfwkgs1k0.fsf@nuthaus.mib.org...
> >> > blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> writes:
> 
> >> >> And then you disallow one legitimate input ....  Well, I guess
> 
> >> > So I can't enter -2147483648.  Oh, darn.  8-)}
> 
> >> I think he meant the -999 that is used to stop the program...
> >
> > I'm not sure who "he" is in this sentence (and for once I'm not just
> > making my usual quibble about the gender of the pronoun).
> 
> It seems I interpreted your "And then" in the wrong way.
> 
> As for "he", that did mean you, but in the absence of clear evidence 
> otherwise, it's often taken to mean "he" or "she". Especially around here..

I don't notice it happening more here than in other newsgroups, but
yeah, it's not unusual usage.  It still bugs me, but I just had that
debate in another newsgroup, and -- eh.  "Get over it", maybe.

> > I'll agree that using some particular value to mean "no more input"
> > doesn't seem as satisfactory as just using end of file, though it's
> > not unusual in a beginning program and maybe not even very bad in
> > that context.
> 
> Yes, at least the user knows that -999 is not an input, but doesn't know 
> that -2147483648 isn't (and nor are most integers for that matter which 
> aren't in the narrow range of LONG_MIN(+1) to LONG_MAX.) But proper range 
> checking would be far too difficult for a beginner's exercise.

Now that you mention range checking .... That's *almost* a valid
argument for using 0x80000000 [*] to mean "invalid", since it's
not a value that's within the range specified by the standard for
"long".  Then again, the fact that it isn't within that range means
it can't be returned from the function without at least impairing
portability ....

Which comes back to the real problem, which is how you signal errors
when all possible return values could be legit.

-- 
B. L. Massingill
ObDisclaimer:  I don't speak for my employers; they return the favor.

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


#10050

From"Bartc" <bc@freeuk.com>
Date2011-09-09 13:59 +0100
Message-ID<j4d2kc$j5$1@dont-email.me>
In reply to#9955
"blmblm@myrealbox.com" <blmblm.myrealbox@gmail.com> wrote in message 
news:9ckpavFv7eU1@mid.individual.net...


> Which comes back to the real problem, which is how you signal errors
> when all possible return values could be legit.

There are ways. For example, reserve one legit value for an 'escape' code.

If such a code is returned, it means the function should be interrogated 
once more. If it returns the same code (or some other agreed value), then 
the function wants to return the escape number as data. Otherwise it's an 
error code (and this allows any number of error codes).

(The function does need to remember some state, and this method depends on 
being able to do two successive, uninterrupted calls, and it depends on the 
caller remembering to do so!)

-- 
Bartc 

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


#9878

From"BartC" <bc@freeuk.com>
Date2011-09-02 10:43 +0100
Message-ID<j3q9cb$um8$1@dont-email.me>
In reply to#9752
"BartC" <bc@freeuk.com> wrote in message news:j3kvds$ihr$1@dont-email.me...

>  else
>    printf("\nThe %ldth integer read was %ld\n", i++, num);

I still find it grating that this prints "1th", "2th", and "3th"!

This does it better:

int i=1;   
char* s;
...

  else {
    switch (i%100){
    case 11: case 12: case 13: s="th"; break;
    default:
      switch (i%10){
      case 1: s="st"; break;
      case 2: s="nd"; break;
      case 3: s="rd"; break;
      default:s="th";
      }
    }
    printf("\nThe %ld%s integer read was %ld\n", i++, s, num);
  }

Or just change to:

    printf("\nInteger #%d read was %ld\n", i++, num);

-- 
Bartc 

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


#9829

FromJoe Pfeiffer <pfeiffer@cs.nmsu.edu>
Date2011-09-01 12:02 -0600
Message-ID<1br540b0oo.fsf@snowball.wb.pfeifferfamily.net>
In reply to#9730
Jack <spamtrap@trashcan.invalid> writes:
>
> COMSC 1613 Programming I (C)       Programming Assignment
> 3                
>
> In this assignment, you will write a 'C' function that will approximate
> the action of the command scanf("%d",&x); namely, to read ASCII
> character
> digits from the standard input stream and convert/interpret the sequence
> into a binary integer.

Since the author of scanf() did it, you *know* it's not impossible.
-- 
"Erwin, have you seen the cat?" -- Mrs. Shroedinger

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


#9833

FromJames Kuyper <jameskuyper@verizon.net>
Date2011-09-01 15:12 -0400
Message-ID<4E5FD915.30806@verizon.net>
In reply to#9829
On 09/01/2011 02:02 PM, Joe Pfeiffer wrote:
> Jack <spamtrap@trashcan.invalid> writes:
>>
>> COMSC 1613 Programming I (C)       Programming Assignment
>> 3                
>>
>> In this assignment, you will write a 'C' function that will approximate
>> the action of the command scanf("%d",&x); namely, to read ASCII
>> character
>> digits from the standard input stream and convert/interpret the sequence
>> into a binary integer.
> 
> Since the author of scanf() did it, you *know* it's not impossible.

Your conclusion is correct, but your argument is faulty. There's no
requirement that standard library functions be written in C, and in fact
many of them are standard library functions precisely because they do
things that can't be done using just the C language. They're either
written in some other language (often assembler) or they call
OS-specific functions which are themselves written in some other language.

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().

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


#9834

Fromsandeep <nospam@nospam.com>
Date2011-09-01 19:36 +0000
Message-ID<j3oms2$tg7$2@speranza.aioe.org>
In reply to#9833
James Kuyper 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().

I believe the following to be a conforming implementation of fgetc, 
entirely in C code:

int fgetc(FILE *stream)
{
  errno = EIO;
  return EOF;
}

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


#9839

FromJoe Pfeiffer <pfeiffer@cs.nmsu.edu>
Date2011-09-01 14:53 -0600
Message-ID<1bmxeoass1.fsf@snowball.wb.pfeifferfamily.net>
In reply to#9833
James Kuyper <jameskuyper@verizon.net> writes:

> On 09/01/2011 02:02 PM, Joe Pfeiffer wrote:
>> Jack <spamtrap@trashcan.invalid> writes:
>>>
>>> COMSC 1613 Programming I (C)       Programming Assignment
>>> 3                
>>>
>>> In this assignment, you will write a 'C' function that will approximate
>>> the action of the command scanf("%d",&x); namely, to read ASCII
>>> character
>>> digits from the standard input stream and convert/interpret the sequence
>>> into a binary integer.
>> 
>> Since the author of scanf() did it, you *know* it's not impossible.
>
> Your conclusion is correct, but your argument is faulty. There's no
> requirement that standard library functions be written in C, and in fact
> many of them are standard library functions precisely because they do
> things that can't be done using just the C language. They're either
> written in some other language (often assembler) or they call
> OS-specific functions which are themselves written in some other language.

Sorry, "Since the author of scanf() did it in C, you *know* it's not
impossible."

> 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?
-- 
"Erwin, have you seen the cat?" -- Mrs. Shroedinger

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


#9842

FromKeith Thompson <kst-u@mib.org>
Date2011-09-01 16:01 -0700
Message-ID<ln8vq7sw91.fsf@nuthaus.mib.org>
In reply to#9839
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.

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


#9844

FromJoe Pfeiffer <pfeiffer@cs.nmsu.edu>
Date2011-09-01 17:22 -0600
Message-ID<1bty8vrgpn.fsf@snowball.wb.pfeifferfamily.net>
In reply to#9842
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?

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


#9853

Frompete <pfiland@mindspring.com>
Date2011-09-01 19:39 -0400
Message-ID<4E6017A1.4170@mindspring.com>
In reply to#9844
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?

This doesn't exactly answer your question,
but getc and fgetc are very close in what they do.

There is some chance that if getc 
is implemented on you machine as a macro,
that you can use the following program
to see how the implementation that you are using,
implements getc.

/* BEGIN new.c */

#include <stdio.h>

#define str(x)  # x
#define xstr(x) str(x)

int 
main(void)
{
    puts(xstr(getc(stdin)));
    return 0;
}

/* END new.c */


-- 
pete

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


#9854

FromKeith Thompson <kst-u@mib.org>
Date2011-09-01 16:39 -0700
Message-ID<ln4o0vsuhl.fsf@nuthaus.mib.org>
In reply to#9844
Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
> 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?

It could be implemented on top of some other input routine, but
eventually *something* has to perform some system-specific action to
perform the actual input (such as calling read(), for example).

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


#9856

FromJoe Pfeiffer <pfeiffer@cs.nmsu.edu>
Date2011-09-01 18:51 -0600
Message-ID<1bzkinzs03.fsf@snowball.wb.pfeifferfamily.net>
In reply to#9854
Keith Thompson <kst-u@mib.org> writes:

> Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
>> 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?
>
> It could be implemented on top of some other input routine, but
> eventually *something* has to perform some system-specific action to
> perform the actual input (such as calling read(), for example).

Well, sure, but by that definition his assignment really is impossible,
since it calls for him to get input from stdin.

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


#9861

Frompete <pfiland@mindspring.com>
Date2011-09-01 22:27 -0400
Message-ID<4E603F20.5EAC@mindspring.com>
In reply to#9856
Joe Pfeiffer wrote:

> Well, sure,
> but by that definition his assignment really is impossible,
> since it calls for him to get input from stdin.

"The function scan_int will use getchar()"

-- 
pete

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


#9863

FromJames Kuyper <jameskuyper@verizon.net>
Date2011-09-01 22:53 -0400
Message-ID<j3pgej$2c7$1@dont-email.me>
In reply to#9856
On 09/01/2011 08:51 PM, Joe Pfeiffer wrote:
> Keith Thompson <kst-u@mib.org> writes:
> 
>> Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
>>> 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?
>>
>> It could be implemented on top of some other input routine, but
>> eventually *something* has to perform some system-specific action to
>> perform the actual input (such as calling read(), for example).
> 
> Well, sure, but by that definition his assignment really is impossible,
> since it calls for him to get input from stdin.

The problem statement specifically allows scan_int() to call getchar(),
which is sufficient to achieve the specified goal.

I was making the distinction between scanf(), which can be implemented
entirely in terms of calls to lower level C standard library functions,
and fgetc(), which cannot. Your argument that scan_int() could be
implemented in C, since scanf() was implemented in C, didn't make that
distinction.

Your conclusion was basically correct, but reaching that conclusion can
be justified only by careful examination of the specification of scanf()
and a comparison with the restrictions imposed on the implementation of
scan_int(). Such an analysis leads to the conclusion that it's not
possible for x = scan_int() to match the locale-dependence of the
behavior of scanf("%d",&x), since calls to isspace() are prohibited, but
the assignment is otherwise feasible.
-- 
James Kuyper

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


#9885

FromKenneth Brody <kenbrody@spamcop.net>
Date2011-09-02 10:45 -0400
Message-ID<xv-dnYGDi8-1cf3TnZ2dnUVZ_oWdnZ2d@bestweb.net>
In reply to#9856
On 9/1/2011 8:51 PM, Joe Pfeiffer wrote:
> Keith Thompson<kst-u@mib.org>  writes:
>
>> Joe Pfeiffer<pfeiffer@cs.nmsu.edu>  writes:
>>> Keith Thompson<kst-u@mib.org>  writes:
[...]
>>>> fgetc() cannot be written in *portable* C.
>>>
>>> What in it requires non-portable C?
>>
>> It could be implemented on top of some other input routine, but
>> eventually *something* has to perform some system-specific action to
>> perform the actual input (such as calling read(), for example).
>
> Well, sure, but by that definition his assignment really is impossible,
> since it calls for him to get input from stdin.

Given that definition, this isn't portable, either:

     int main(int argc,char *argv[]) { return(0); }

because it requires system-specific start-up code in order for main() to be 
executed.  (And use a system-specific method of returning zero from a function.)

-- 
Kenneth Brody

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


#9887

FromJames Kuyper <jameskuyper@verizon.net>
Date2011-09-02 11:02 -0400
Message-ID<4E60EFEB.2030609@verizon.net>
In reply to#9885
On 09/02/2011 10:45 AM, Kenneth Brody wrote:
> On 9/1/2011 8:51 PM, Joe Pfeiffer wrote:
>> Keith Thompson<kst-u@mib.org>  writes:
...
>>> It could be implemented on top of some other input routine, but
>>> eventually *something* has to perform some system-specific action to
>>> perform the actual input (such as calling read(), for example).
>>
>> Well, sure, but by that definition his assignment really is impossible,
>> since it calls for him to get input from stdin.
> 
> Given that definition, this isn't portable, either:

I think you're using some other, massively more restrictive definition
than the one Keith was using.

>      int main(int argc,char *argv[]) { return(0); }
> 
> because it requires system-specific start-up code in order for main() to be 
> executed.  (And use a system-specific method of returning zero from a function.)

How does that affect the portability of that code? There's nothing that
the code needs to do about that; a conforming implementation of C is
required to do whatever it needs to do to make the system-specific
aspects you refer to work.
On the other hand, a conforming implementation of C is not required to
make a call to the POSIX function read() work, since it need not be on a
POSIX-conforming system.

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


#9889

FromKeith Thompson <kst-u@mib.org>
Date2011-09-02 08:05 -0700
Message-ID<lnzkinq91n.fsf@nuthaus.mib.org>
In reply to#9856
Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
> Keith Thompson <kst-u@mib.org> writes:
>> Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
>>> 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?
>>
>> It could be implemented on top of some other input routine, but
>> eventually *something* has to perform some system-specific action to
>> perform the actual input (such as calling read(), for example).
>
> Well, sure, but by that definition his assignment really is impossible,
> since it calls for him to get input from stdin.

I think we can assume that he's allowed to call fgetc(), or fgets(),
or 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]


#9891

FromKeith Thompson <kst-u@mib.org>
Date2011-09-02 08:17 -0700
Message-ID<lnvctbq8i0.fsf@nuthaus.mib.org>
In reply to#9889
Keith Thompson <kst-u@mib.org> writes:
> 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 think we can assume that he's allowed to call fgetc(), or fgets(),
> or something similar.

And in fact the assignment specifically allows (in fact, requires)
the use of getchar().

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


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

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


csiph-web