HDTenEightyP/NetNews huggingface dataset:
From: netapp@netcom.com (Byron Rakitzis)
Subject: Re: Most difficult part of learning C?
Date: Thu, 27 Aug 92 05:45:08 GMT
Organization: Netcom - Online Communication Services  (408 241-9760 guest) 

Pointers: Learning the difference between different types of pointers,
and the issue array-pointer confusion.

Declaration syntax: declaring arrays of function pointers, for example,
is something I occasionally have to drag out cdecl for to this day.

Operator precedence: the precedences are hard to learn, also order of
evaluation of expressions is something that can bite you while learning
C. e.g., here's a hypothetical error a tyro could easily make:

	int read100() {
		return ((getchar()-'0')*10) + (getchar()-'0');
	}

(and never mind not checking the return value of getchar() for now.)

A very confusing example in this vein is arglists: syntactically they
resemble a comma-separated list of expressions, but unlike a comma-
separated list of expressions, left-to-right order of evaluation is
not guaranteed.

I guess I should add typedefs, too. They took a while to understand.
Newsgroups: comp.lang.c
From: u8903845@cs.uow.edu.au (Anil Sachdeva)
Subject: dynamic arrays
Keywords: dynamic arrays
Organization: Dept of Computer Science, Wollongong University, Australia
Date: Wed, 2 Sep 1992 16:40:18 GMT

Hello 

I would appreciate if somebody could send me some program or example.
where Dynamic array is used , rather than the normal ones.

Your help would be appreciated .

Thanks

email

u8903845@cs.uow.edu.au
Date: Mon, 31 Aug 92 07:56:00 +0200
From: Gilles_Kohl@spam.fido.de (Gilles Kohl)
Subject: How is NaN recognized?
Newsgroups: comp.lang.c
X-Comment-To: (Jos Horsmeier)
Organization: To take arms against a C of troubles ... 

 > From: jos@and.nl (Jos Horsmeier)
 > In article <5569@ucsbcsl.ucsb.edu> 6500mack@ucsbuxa.ucsb.edu (Michael P.
 > Mack) writes:
 > |I am using scanf() to read in a float that is entered by the user.  If
 > |an invalid string is typed such as "-" or "." then the variable is
 > |assigned -0.NaN(DFD5480000000000... or -0.NaN(DFD9400000000000000...
 > |
 > |How do I detect when the float is a NaN so that I can set it to 0.0?

 > Don't use scanf() for this, use a combination of fgets(), to read a line
 > and atof() to convert the input string to a double value. atof() returns
 > 0.0 if the string could not be converted to a double value and it
 > sets (I'm not sure if all implementations do this) the errno variable
 > to ERANGE in case of overflow.

Jos,

another alternative (beside your suggested use of a finite automaton)
might be the strtod function from the ANSI standard lib:

double strtod(const char *s, char **enpd)

strtod returns HUGE_VAL in case of overflow, 0 in case of underflow - in both 
cases the standard requires errno to be set to ERANGE. What's really nice about 
strtod is that it sets the char * pointed to by enpd to where it stopped 
converting - makes error detection easier.

Regards,
Gilles.

---
Newsgroups: comp.lang.c,comp.unix.programmer
From: news@dbserver.kaist.ac.kr (News)
Subject: Re: Realloc question
Reply-To: pckim@dbserver.kaist.ac.kr
Organization: Korea Advanced Institute of Science and Technology (KAIST)
X-Newsreader: Tin 1.1 PL5
Date: Fri, 4 Sep 92 17:13:53 GMT

swanger@ducvax.auburn.edu wrote:
: I think I need to use realloc in a program, but I'm not sure I understand
: how to use it.  My program will dynamically allocate a two-dimension array
: of strings using calloc statements.  There is a chance that I might need
: to increase the size of this array later in the program, so I guess I need
: to use realloc.  Here is a code fragment:
: 
: -----------------------------------------------------------------------
: 
: int num_strings, string_size, loop,;
: char **strings;
: 
: num_strings = 100  /* will actually be entered by user */
: string_size = 100  /* ditto                            */
: 
: strings = (char **) calloc(num_strings, sizeof(char*));
: 
: for (loop = 0; loop < num_strings; loop++)
: {
:    strings[loop] = (char *) calloc(string_size, sizeof(char));
: }
: 
: -----------------------------------------------------------------------
: 
: 
: Somewhere later in the program, I discover that I need more more strings. 
: Is the following syntax correct?
: 
: 
: strings = (char **) realloc((char **) strings, new_num_strings);
: 

This line should be changed as

strings = (char **) realloc((char **) strings, new_num_strings * sizeof(char *));

provided that new_num_strings = num_strings + alpha that you want more.

: 
: I don't want the existing strings to be longer, I just want to allocate more
: pointers that can also be calloc'ed as strings.
: 
: I read the man pages for realloc on my system (SUN IPC, SUNOS 4.1.2) and I
: THINK this is how to use it.  I would definitely appreciate help with this.
: 
: Thanks in advance!!
: -- 
: David Swanger,   Auburn University, Alabama,   swanger@ducvax.auburn.edu 
:                                                swanger@mail.auburn.edu

--
Pyung-Chul Kim			Internet: pckim@dbserver.kaist.ac.kr
Dept. of CS, Korea Advanced Inst. of Science and Technology (KAIST)
373-1 Kusong-dong, Yusong-gu Taejon 305-701, Korea
TEL: +82-42-869-5570	FAX: +82-42-869-3510
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.lang.c
Subject: Re: LALR grammar for "C"
Date: 30 Aug 92 16:18:14 GMT
Reply-To: dave@cs.arizona.edu (Dave Schaumann)
Organization: University of Arizona

In article <0095FD20.B9F045C0@Ercvx1.erc.montana.edu>, osymg@Ercvx1 (Marcus Giese) writes:
>       Hello, I'm looking for a "C" LALR grammar definition.  Obviously
>I'd prefer one in a "yaccable" form, but any form would do.

Check out Jim Roskind's grammar.  It can be found at ics.uci.edu in the
ftp/pub directory as c++-grammar.tar.Z (it also includes a yacc grammar
for C++, thus the name).

This archive also includes a (f)lex file for C++ (no symbol table though,
so a small liberty is taken with typedef names).

You'll probably also want to grab the Berkely yacc implementation at
the same site (byacc.tar.Z), since Jim also includes a special skeleton
file which will print out a nice parse tree for you.

-- 
Dave Schaumann			dave@cs.arizona.edu
From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
Newsgroups: comp.lang.c
Subject: Re: Novice Questions
Date: 31 Aug 92 07:01:23 GMT
Organization: University of Helsinki

ckincy@mcs213c.cs.umr.edu (Charles Kincy) writes:
>>The latter is by definition: the language is defined that way.  The
>>former follows directly from the latter: foo[0] <=> *(foo+0) <=> *(foo)
>><=> *foo.
>
>Beware!  If you define foo as a char[], you may not reassign foo in
>any way or you will be punished by a wet noodle. =)

Quite correct (except for the noodle part), but also quite irrelevant.
The *(foo+x) <=> foo[x] identity works regardless of whether foo is a
pointer or an array.

>Many novices fall into this trap.  Arrays and pointers are *nearly*
>equivalent, but not quite.

Arrays and pointers are nowhere near equivalent.  Superficially they
might look so, but that is only because arrays usually automatically
become pointers in C (but sometimes don't).  For more information,
please read the FAQ of this group, section 2 especially.

Btw, the person who said that array names are constant pointers might
want to look at questions 2.6.

--
Lars.Wirzenius@helsinki.fi
Xref: sparky comp.lang.c:12858 comp.std.c:2522
From: ccx018@cch.coventry.ac.uk (Leslie Griffiths (Griff))
Newsgroups: comp.lang.c,comp.std.c
Subject: Re: strcpy implementation question
Date: 27 Aug 92 13:23:06 GMT
Organization: Coventry University

In article <23531@alice.att.com> ark@alice.UUCP () writes:
>In article <1992Aug23.194919.22007@iecc.cambridge.ma.us> johnl@iecc.cambridge.ma.us (John R. Levine) writes:
>
>> 	static char buf[6];
>
>> 	strcpy(buf+3, "cd");
>> 	strcpy(buf, "ab");
>
>> If buf doesn't end up containing "ab\0cd\0" I'd say that something was
>> seriously wrong.
>
>If you make that "abcd\0", I'll agree with you.

I think Mr Levine is correct. The second strcpy copies a and b to locations
buf[0] and buf[1], and then a null, so we have:

	buf[0] = a, buf[1] = b, buf[2] = \0

>				--Andrew Koenig


Cheers


-- 
Griff				\\         	ccx018@uk.ac.cov
^^^^^		       		 :-=       	^^^^^^^^^^^^^^^^
		        	//
From: bharat@ccvax.ucd.ie
Newsgroups: comp.lang.c
Subject: compare socket based and RPC based.....
Date: 25 Aug 92 13:58:51 GMT
Organization: University College Dublin

Hi Net Gurus,
 
could any one tell me the advantages of "Socket Based interprocess
communication" over "Remote Procedure Call based interprocess communication"?

My application program runs on the top of the packet layer. It communicates 
with a X.25 switch. The communication between switch and application programm
is based on 'BSD Socket based communication'.

I summarize it in the following steps- 

1. I open a socket in X.25 domain (i am using SunNet X.25 software).

2. Pass the address of remote switch to the socket.

3. send some data (e.g. 'stat' command for the switch which gives all the 
statstical information from the switch). 

4. receive the output (e.g. output of 'stat' command which is parameter values 
from the switch).

             ----------------------------------------------------------

My questions are: 

1.why and when the socket based communication is used?

2.Why always RPC based communication is prefered over socket based 
communication is prefered?

3. Is it possible to implement a 'Client-Server' model using  sockets? if yes,
can i call 'My-application-program=X.25-switch' (as given in steps 1-4) as
a 'cleint=server' model?


Any pointers/hints..? Thanks very much for reading this. I will welcome any
concern information.

Please ..send your answers by email to me.

- Bharat

(bharat@ccvax.ucd.ie)
From: banshee@cats.ucsc.edu (Wailer at the Gates of Dawn)
Newsgroups: comp.lang.c
Subject: Re: Could someone email me a pointer to the 'bignum' package?
Date: 31 Aug 92 22:52:00 GMT
Organization: University of California, Santa Cruz
NNTP-Posting-Host: am.ucsc.edu


	Try gmp2.2 from prep.ai.mit.edu

	Based (loosely) on the original bsd mp library.

-- 
The Wailer at the Gates of Dawn              | banshee@cats.UCSC.EDU       |
Just who ARE you calling a FROOFROO Head?    |                             |
DoD#0667  "Just a friend of the beast."      | banshee@ucscb.UCSC.EDU      |
2,3,5,7,13,17,19,31,61,89,107,127,521,607....| banshee@ucscb.BITNET        |
Newsgroups: comp.lang.c
From: sullivan@alw.nih.gov (Jim Sullivan)
Subject: Re: Most difficult part of learning C?
Organization: National Inst. of Health, DCRT, CSL
Date: Wed, 26 Aug 1992 12:46:52 GMT

In article <9208251159.AA04122@ult4>, goldstei@cgi.com ("Morris Goldstein") writes:
|> I am conducting research for a little project concerning difficulties in
|> learning C and how to improve the teaching of C so as to circumvent these
|> problems.
|> 
|> When learning C, what things did you find the most confussing/difficult to
|> understand?

What else?... POINTERS!
-- 
Jim Sullivan 		[ The future ain't what it used to be ]
National Institutes of Health
Bethesda, MD 20892
Phone: (301) 496-5362
FAX: (301) 402-2867
Internet: sullivan@alw.nih.gov
From: harrison@lclark.edu (Mark Harrison)
Newsgroups: comp.lang.c
Subject: Re: main()
Date: 3 Sep 92 16:00:01 GMT
Article-I.D.: lclark.1992Sep3.160001.13782
Organization: Lewis & Clark College, Portland OR

In article <9224708.25973@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus
James HENDERSON) writes: >harrison@lclark.edu (Mark Harrison) writes: >
>>In my programs, I use 'void main()' and never had any problems doing so. 
>>These are written with Turbo C/C++ 3.0, so I don't know about any
others. > >Well, I guess you were just lucky then. >Try compiling with
"-A" ("Ansi" - disable extensions) and "-P" (Compile as >a C++ program).
With these options, Turbo C/C++ 1.0 gives me a compile error. > OK.  I now
understand why it is important not to declare 'void main()'.  I never
thought of it before.  But two people have now told me to try it with -A
and -P.  Why?  I don't really need to satisify my curiosity about 'void
main()'.  So is there another reason I would want these switches?  My
program would most definatly not be portable.  I'm writing a GUI for DOS
and I doubt that it would run without major modifications on another
system.  And I am very happy with Borland's product, and don't see myself
switching in the near future. 


-- 
=============================================================================
Mark Harrison           |  "We are the Priests, of the Temples of Syrinx
harrison@sun.lclark.edu |   Our great computers fill the hallowed halls."
              -- Me     |                                    -- Rush
Xref: sparky comp.lang.c:12679 comp.sys.sun.misc:3856
From: may@Apple.COM (Patrick May)
Newsgroups: comp.lang.c,comp.sys.sun.misc
Subject: How to use the same file of structs on PC and Sun?
Date: 23 Aug 92 02:07:49 GMT
Organization: Apple Computer Inc., Cupertino, CA

Hi,

     I'm porting an application from an MS-DOS environment to the Sun
(SunOS 4.1.1).  The app makes heavy use of files opened in binary mode
to store various structs.  When I tried to use these same files on the
Sun I found that the Sun compiler came up with a different size for
these structs than did the MS-DOS compiler (uSoft).  I'd half expected
something like this, and had intended to do a one-time conversion of
the affected files.

     Unfortunately, these files may be accessed by the both the Sun
and MS-DOS versions of the application over, for example, PC/NFS.
Is there a way to tell the Sun compiler not to do any alignment (if
in fact that's what's happening) or, alternatively, to tell the
Microsoft compiler to act the same as the Sun compiler?

Thanks,

Patrick May
may@apple.com     (posting from, but not working or speaking for, Apple)
------------------------------------------------------------------------
                              "A contract programmer is always intense."
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.lang.c
Subject: Re: Most difficult part of learning C?
Date: 31 Aug 92 17:18:06 GMT
Reply-To: dave@cs.arizona.edu (Dave Schaumann)
Distribution: usa
Organization: University of Arizona

In article <714939390@romeo.cs.duke.edu>, trt@duke (Tom Truscott) writes:
>The biggest difficulty in learning C that I have encountered
>is the lack of a hand-holding coding&testing environment.

Yeah.  One of the first programs I wrote did some simple array manipulation.
I couldn't figure out why it was crashing on exit.  After much head-scratching
and code dissection, I finally realized that I was accessing my arrays from
1 to N instead of 0 to N-1.

Now, the fact that C will let you do just about anything you want is very
useful to the experienced programmer, but it also has the tendency to
ensnare the neophyte.

IMHO, I think that new programmers can profitably start out in C -- they
just need to be aware of the pitfalls.  Even a short list of rules could
be eminantly helpful.  But if you just send them out there with no
preperation... all you're going to get is a roomfull of students that hate C.

>A difficulty I have not seen mentioned is in learning how
>to use the boolean operators & | ^ ~.

Of course, these are not boolean operators -- they are bit operators.
But I agree.  They can easily be skipped.

>Some difficulties can be circumvented by avoiding them entirely.
>In my opinion the following can be omitted:
[...]
>    enumerated types

What?!  Noooo!  Enumerated types are an incredibly useful feature!
The ability to give things a symbolic name is essential to good
programming.

[...]
>    typedefs

Similarly with typedefs.  Perhaps you don't need them in a first semester
programming class, but I wouldn't delay introducing them past the second
semester.  Like symbolic names, the ability to construct abstract types
(as opposed to clusters of structs and pointers) is essential to programming.

>Is the purpose of the course to explore every last corner of the C language,
>or is it to teach some topic for which C happens to be appropriate?

IMHO, the purpose of the course should be to teach programming first, and C
second.  If approached in the right manner, C's draw-backs can even be used
to advantage in a programming course (show how to program defensively, show
the importance of formatting your code reasonably, and choosing good variable
names, etc., etc.)

-- 
Dave Schaumann			dave@cs.arizona.edu
From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
Newsgroups: comp.lang.c
Subject: Re: Why should POINTERS be so damn hard to understand ?
Date: 2 Sep 92 05:52:40 GMT
Organization: Comp Sci, RMIT, Melbourne, Australia

In article <1992Aug28.012406.3698@ttinews.tti.com>, reid@metis.tti.com (Reid Kneeland) writes:
> True.  If you think of C as a preprocessor for the PDP-11 assembler, it
> makes a lot more sense.

Of course, if you _do_ think of C that way, you will be committing the
sin of anachronism.  Most of C's control structures are copied from BCPL
(designed for word-oriented machines) except that BCPL had separate BREAK
and ENDCASE statements, and C confounds the two; C's update operators were
very popular at the time it was designed and were mostly present in Algol 68
(C didn't copy the PRUS operator though).  The PDP-11 was _not_ the first
machine C ran on, nor the machine C was designed for.

-- 
You can lie with statistics ... but not to a statistician.
Newsgroups: comp.lang.c
From: alpha@wyvern.twuug.com (Joe Wright)
Subject: Re: calloc() confusion -- help?
Organization: Box 68621, Virginia Beach, 23455
X-Newsreader: Tin 1.1 PL4
Distribution: na
Date: Fri, 4 Sep 1992 13:32:18 GMT

bob@kc2wz.bubble.org (Bob Billson) writes:
: Hi all,
: 
: I tried posting this the other day.  I doubt it got out as my news feed
: seems to be broke (at least news has gone down to a trickle for the past few
: days.)  If this is a repeat, I apologize.  I would appreciate any answers be
: sent email.  Thanks.
: 
: I hope someone can unblock my mental block.  I am trying to figure out how to
: properly use calloc() to create an array of structures.  Here is an example of
: my test program.  It won't compile properly and I seem to have a mental block
: figuring out why it won't compile and work correctly..  I need this to compile
: under the "old style" K&R not ANSI.
: 
: "test.list" is a text file with < 80 chars per line of various info.  As
: each line is read, the appropriate pieces need to be placed each struct member.
: Because the number of lines in "test.list" will vary, I want to dynamically
: allocate an array of structures mbox at runtime.
: 
: 
: #include <stdio.h>
: 
: 
: struct mbox  {
:         char status,
:              envelop[14],
:              from[19],
:              subj[37];
:     };
: 
: 
:  
: main()
: {
:      FILE *fp;
:      int i, limit;
:      register struct mbox *ltr;
:      char line[81];
: 
: 
:      if ((fp = fopen ("test.list", "r")) == NULL)
:              fatal ("can't open test.list");
: 
: /*   limit = numlines (fp);  */
: 
:      limit = 35;                    /* for test purposes right now */
: 
:      /* create an array of structs mbox, one for each line in test.file */
: 
:      ltr = (struct mbox *) calloc (limit, sizeof (struct mbox));
: 
:      if (ltr == NULL)
:              fatal ("calloc() can't get enough memory");
: 
:      for (i = 0; i < limit; ++i)
:        {     fgets (line, sizeof (line), fp);
: 
:              ltr[i]->status = line[0];
:              strncpy (ltr[i]->envelop, &line[5], 12);
:              strncpy (ltr[i]->from, &line[14], 18);
:              strncpy (ltr[i]->subj, &line[32], 26);
:        }
: 
:      fclose (fp);
: 
:      /* see if we got what we think we got */
: 
:      for (i = 0; i < limit; ++i);
:        {      printf ("ltr[%d]->status  = %c\n", i, ltr[i]->status);
:               printf ("ltr[%d]->envelop = %s\n", i, ltr[i]->envelop);
:               printf ("ltr[%d]->from    = %s\n", i, ltr[i]->from);
:               printf ("ltr[%d]->subj    = %s\n\n", i, ltr[i]->sb);
:        }
: }
: 
: 
: 
: int fatal (msg)
: char *msg;
: {
:       fprintf (stderr, "foo: %s\n", msg);
:       exit (0);
: }
: 
: 
: I'm sure the answer is simple, I just can't see it.  The C books I do have, do
: not help much with calloc(). :-(
: 
: Thanks for the help!
:  
:       Bob

Maybe not a calloc() problem.  You access the array improperly.
As ltr is a pointer to structure, the form is 'ltr->member' or
'(ltr+i)->member' rather than 'ltr[i]->member'.  If you want to
use the subscript, it should be 'ltr[i].member'.

-- 
Joe Wright  alpha@wyvern.twuug.com
From: jfw@ksr.com (John F. Woods)
Newsgroups: comp.lang.c
Subject: Re: Most difficult part of learning C?
Date: 27 Aug 92 13:27:27 EDT

arensb@kong.gsfc.nasa.gov (Andrew Arensburger - RMS) writes:
>	Now, if the ANSI committee had defined a type 'byte' to be of
>the smallest size that can be represented on the host architecture,
>it would have made sense.

You'd have confused a lot of people who discovered that sizeof(char) was now
fractional.

(A word-oriented architecture can still have special byte pointers, or the
compiler can even invent them itself if it must).
Xref: sparky comp.lang.c:12864 comp.unix.programmer:4467
From: max@underg.UUCP (Max Cray)
Newsgroups: comp.lang.c,comp.unix.programmer
Subject: I/O With Unix/C
Date: Thu, 27 Aug 92 12:22:58 EDT
Organization: Underground Computing Foundation

Help!

I am trying to do the most basic file I/O on a couple of unix machines (HP835,
and Sequent S27), and I can not get it to work. For example:

#include <stdio.h>
main()
{
    int c;

    while (c = getchar() != NULL)
        putchar(c);
}

On a DOS machine you just compile it, and it works. When I compile it on
a unix machine, it compiles and runs, but I can't seem to redirect input
and output through it.

ls -l | myfilter > outfile.tmp

If I type the following command it runs, but it still expects the I/O to
come from the keyboard, and go to the screen.

What am I missing?

Please mail replies.

thanks,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 -= Max Cray =-                                       
 Net:     underg%max@uunet.uu.net                   Don't be afraid;
 UUCP:    ...!uunet!underg!max                       just believe.
 CI$:     76334,2203                                  
Newsgroups: comp.lang.c,news.answers
From: karl@ima.isc.com (Karl Heuer)
Newsgroups: comp.lang.c
Subject: Re: printf question
Date: 1 Sep 92 21:47:25 GMT
Article-I.D.: ima.1992Sep01.214725.6334
Organization: Interactive Systems, Cambridge, MA 02138-5302

In article <kimcm.714943581@login.dkuug.dk> kimcm@login.dkuug.dk (Kim Chr. Madsen) writes:
>Using this syntax on the original problem will save you some time because the
>format is evaluated at compile time instead of run time.

On the other hand, when the printf interpreter encounters the format "%04x",
it has to convert the string "4" into the integer value 4; whereas with "%0*x"
it can just pull the value out of the argument list.  I seem to recall hearing
that somebody actually found "%0*x" to be faster.  (A test on my system just
now indicates that it may be 1/3 of a percent faster.)

Of course, this is not likely to be a bottleneck in any case.  I would use "*"
for portability reasons (Classic C doesn't have string pasting), and because
it avoids having to hardcode the string form of the magic constant.  (The C
preprocessor has no way to evaluate-and-stringize a constant expression.)

Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint
Newsgroups: comp.lang.c