HDTenEightyP/NetNews huggingface dataset:
From: sca@gese.ge14.mdadv.gv.at (Petzi Schweda)
Newsgroups: comp.lang.c
Subject: Re: Parameter passing & data abstraction
Date: 31 Dec 92 07:49:04 GMT
Organization: MD-ADV, Vienna, Austria
Distribution: world
NNTP-Posting-Host: gese.ge14.mdadv.gv.at
Originator: sca@gese0n.ge14.mdadv.gv.at


In article <1992Dec30.184135.1963@organpipe.uug.arizona.edu>, dave@cs.arizona.edu (Dave Schaumann) writes:
|> It has come to me that C's mechanisms for parameter passing are less than
|> wonderful.  For instance, in defining some data structure, my typical
|> stratagy is to create a .h file with the struct definition, appropriate
|> typedefs, and #defines for simple functions.
|> 
|> The root of the problem is that I want to pretend that macros are really
|> in-line functions.  However, "macro functions" display "call by reference"
|> behavior, while real functions have call by value behavior.
|> 
|> One solution is to always pass pointers -- in effect, change the default
|> parameter behavior (for structs, anyway) to be call-by-reference.

After coding a whole bunch of system modules I would consider this:
No exported macros at all - use functions instead ...
Furthermore highly encapsulate thy data, not exporting any structures:
	#ifdef MODULE_PRIVATE
	typedef struct ModuleDataRec
		{....
		} ModuleDataRec, *ModulData;
        #define SetMember(d, v) (*d).member = v; 
	#else
	typedef void *ModulData;
	void SetMember(ModulData d, int v);
	#endif;
This technique was forced by using runtime libraries, where you can't ensure that anyone using your module will recompile with a new version (btw for me this would be a contradiction to rtl's) ...
For the VERY few uses where the above will lead into performance-troubles, grant them MODULE_PRIVATE, with all it's disadvantages ...
On performance: I think that on risc systems the calling overhead is no problem after all (on DEC Alpha, the first six parameters are passed through registers, and there's nearly no call frame to be built ...), under VAX-VMS (and on other systems doing lots on the stack) it can get a problem ...

regards,
###################################################
Petzi Schweda (sca@gese.ge14.mdadv.gv.at)
MD-ADV, Municipality of the City of Vienna, Austria


Newsgroups: comp.lang.c
From: rob@magrana1.uucp (Rob Duncan)
Subject: floating point arithmetic
Organization: Pomegranate Technology, Inc.
Date: Tue, 22 Dec 1992 08:43:22 GMT

Has anyone come across code to implement floating point arithmetic
with C integers?  I am writing a C compiler and I need run-time
support for floating point operations.  I'm initially concerned with
correctness and conformance to a standard (ideally IEEE format floats)
rather than speed.  Eventually I'll drop the code into assembler by
hand (but at the moment the target machine is a moving one 8-).

I've checked the Index of free C or C++ source code for numerical
computation but it doesn't have what I'm looking for.

Thanks,


-- 
Rob Duncan                                       Talk: +1-415-325-8780
Pomegranate Technology, Inc.                      Fax: +1-415-325-8780
235 Embarcadero Road               UUCP: ...!uunet!magrana1!rob.duncan
Palo Alto, CA 94301               Internet: rob.duncan@pomegranate.com
From: bhoughto@sedona.intel.com (Blair P. Houghton)
Newsgroups: comp.lang.c
Subject: Re: character subroutines
Date: 22 Dec 1992 17:20:44 GMT
Organization: Intel Corp., Chandler, Arizona
NNTP-Posting-Host: stealth.intel.com

In article <Bzn59z.K96@netnews.jhuapl.edu> packard@netnews.jhuapl.edu ((Mike Packard, JHU/APL, 301-953-5000 x3516)) writes:
>
>The following is a program which contains three subroutines.  Each
>subroutine is nearly identical.  I can't figure out why the third
>subroutine is the only one that works correctly.  If someone could
>explain to me what is going on in the previous two subroutines, I would
>greatly appreciate it.

See Q 3.4 in the FAQ.

				--Blair
				  "&c."
Xref: sparky comp.lang.c:19040 comp.lang.c++:18555 comp.misc:4729
From: erik@naggum.no (Erik Naggum)
Newsgroups: comp.lang.c,comp.lang.c++,comp.misc
Subject: Re: What is Object Oriented Programming? Is C doomed?
Date: 30 Dec 92 20:00:54 GMT
Reply-To: Erik Naggum <enag@ifi.uio.no>

[John Nagle]
|
|   Look into B-trees for this sort of thing.  But don't look in Knuth's
|   "Art of Computer Programming" for them; they postdate that classic
|   work.

Donald E. Knuth: The Art of Computer Programming, volume 3, Sorting and
Searching, second printing, page 473-480: B-trees:

"A new approach to external searching by means of multiway tree
branching was discovered in 1970 by R. Bayer and E. McCreight [Acta
Informatica (1972), 173-189], and independently at about the same time
by M. Kaufman [unpublished]. ..."

Preface dated "Oslo, Norway; September 1972".  Copyright 1973.



Oslo, Norway
December 1992						Erik Naggum


--
Disclaimer: I was a kid at the time.
From: hun@bigbird.asro.csk.co.jp (Magyar fiuk)
Newsgroups: comp.lang.c
Subject: Re: System Testing
Date: 24 Dec 92 02:16:02 GMT
Organization: Advanced System Research Organization Ltd. Tokyo, Japan

stasica@alumni.cs.colorado.edu (The Legacy) writes:
>
> void memory_test()
> {
>     int *p, i;
      ^^^
>     p=malloc(8388608);       /* Malloc 8M memory */
>     for (i=0;i<8388600;i++)  /* Write to all 8M 1 char at a time */
>         *(p+i)='\0';  /* BTW this doesn't work....why??? (memory violation)*/

Try char instead of int, and cast malloc to char *.
This way *(p+i) means *(p+i*sizeof(int)).

Gerzson Szinyei (hun@bigbird.asro.csk.co.jp)
From: ash+@CMU.EDU (Ashvini Sharma)
Newsgroups: comp.lang.c
Subject: C -> fortran ?
Date: 3 Jan 93 08:45:46 GMT
Article-I.D.: andrew.EfFnFOm00VpcM89o4K
Organization: Junior, Electrical and Computer Engineering, Carnegie Mellon, Pittsburgh, PA

hi folks,
    does anyone know of a program (public domain or not), which can
translate code written in C to FORTRAN?


thanks a lot,
ash
Newsgroups: comp.lang.c
From: simpson@cactus.org (Randall L. Simpson)
Subject: Re: A good book on C ?
Organization: Capital Area Central Texas UNIX Society, Austin, Tx
Date: Thu, 31 Dec 1992 00:34:47 GMT

In article <FISCHER.92Dec30200843@orange.iesd.auc.dk> fischer@iesd.auc.dk (Lars Peter Fischer) writes:
>
>Well, someone already pointed out Harbison and Steele (be sure to get
>the 3rd edition), but be sure to get
>
>  Andrew Koenig: C Traps and Pitfalls, Addison-Wesley, 1989,
>  ISBN 0-201-17928-8
>
>It's a real gem. Brief and to the point, a delight to read, with lots
>of good points on how to use C effectively, on programming style, and
>on programming in general.
>
>/Lars
   
Since I don't think that Koenig's book has received the renown it richly
deserves, I'll second Lars' recommendation.  I own two copies: one for work,
one for home.  Hmmm, come to think of it I own two copies of every book
written by the Bell Labs gang (Kernighan, Bentley, Aho, and Koenig).  There
must be something in Murray Hill's water...
     
-- 
*-----------------------------------------------------------------------------*
Newsgroups: comp.lang.c
From: oleary@staff.tc.umn.edu ()
Subject: Re: Problem with string processing.
Organization: University of Minnesota
Date: Sun, 3 Jan 1993 05:09:35 GMT


In article <1993Jan2.233446.20833@iitmax.iit.edu> matujos@elof.iit.edu
(Joe Matusiewicz) writes, among other things:
 
>         void add_char_to_str(char ch, char *str)
>         {
>1.           char *tmp;
>2.           tmp = (char *) calloc (2*sizeof(char));
>3.           *tmp = ch;
>4.           *(tmp+1) = '\0';
>5.           strcat(str, tmp);
>             free (tmp);
>         }
 
If the size of str is not big enough to handle the appended character, you're
looking at trouble.  I'll assume it is (If I'm wrong, then your code *really*
doesn't do what you want it to).
 
First, your call to calloc is wrong (I'm really surprised your compiler didn't
catch this).  Get yourself a good C reference, like Kernighan and Ritchie's
"The C Programming Language."
 
Second, you don't need to mess with dynamic memory allocation to do what you
want.
 
Third, learn a consistent programming style (e.g., decide on a standard
spacing for function calls).
 
A much better version is:
 
void add_char_to_str(char ch, char *str)
{
        char tmp[2] = {0};
 
        *tmp = ch;
        strcat(str, tmp);
}
 
You may even want to make tmp a static.  You could also change the name of
the function to make it consistent with the standard string functions,
perhaps strcharcat(char *str, char ch)
 
 
+------------------->  Signature Block : Version 4.1  <---------------------+
|                                                                           |
|          "The two most powerful warriors are patience and time."          |
|                                            --- Leo Tolstoy                |
|                                                                           |
+---------------->   Copyright (c) 1993 by Doc O'Leary   <------------------+
Organization: Penn State University
Date: Tue, 29 Dec 1992 23:02:31 EST
From: <JXU3@psuvm.psu.edu>
Newsgroups: comp.lang.c
Subject: Re: Yacc/ BNF Form / HELP!

In addition to Holub's "Compiler Construction in C", the following
book
   "lex & yacc " by John R. Levine, Tony Mason and Doug Brown
    O' Reilly Associates, 2nd Edition, A Nutshell Handbook
is an excellent introduction to the use of the compiler construction
tools lex and yacc.

Atul Ramani
PSUVM
===========
Newsgroups: comp.lang.c
From: gcouger@olesun.okstate.edu (Gordon Couger)
Subject: Re: definition of strncpy stupid?
Organization: Oklahoma State University, Stillwater
Date: Thu, 24 Dec 1992 00:19:12 GMT

In article <16298@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
>I realise this thread has been running for a while, but I think I have
>something new to say
>
>
>In article <1992Dec9.144743.1863@rti.rti.org>, jbs@rti.rti.org writes:
>> In article <1992Dec9.012534.15596@ptsfa.PacBell.COM> dmturne@PacBell.COM (Dave Turner) writes:
>> >>
>> >>I agree with the original poster in that there's a need for a function like
>> >>strncpy() but that null-terminates the target string. I find it a pain in
>> >
>
char *strncpy(char *d,char *s, int count)
    {
    while(*s && count--)
       *d++ = *s++;
    return d
    }
If memory serves me this should do the trick. One of the neatest things
about C is if doesn't suit you you can fix to do what ever you want it
to do. Right or wrong C doesn't care.
Gordon

Gordon Couger
AB5Dg   Agriculture Engineering Oklahoma State University
gcouger@olesun.agen.okstate.edu 405-744-6514 day 744-2794 evenings   
Newsgroups: comp.lang.c
From: behrenss@Informatik.TU-Muenchen.DE (Soenke Behrens)
Subject: Re: C (Kernighan & Ritchie)
Keywords: C (Kernighan & Ritchie)
Organization: Technische Universitaet Muenchen, Germany
Date: Mon, 21 Dec 1992 10:02:26 GMT

etmjaro@crosby.ericsson.se (Jan Rooijackers,5309,9741) writes:

>I'm reading The C programming language from Kernighan & Ritchie and try to
>make the exercise.
>My question have someone the solution of these exercise or can someone tell
>me where I can find them, so that I can look if my solutions are correct.

There's a book with solutions to the exercises, you should get it in all
bookstores that carry computer-related stuff.

Soenke
-- 
===========================================================================
More than silver, more than gold, I need   !    behrenss@informatik.
electricity. I need it for my dreams.      !    tu-muenchen.de
(RACTER)                                   !  FIDO: 2:246/13 Soenke Behrens
Newsgroups: comp.lang.c
From: fischer@iesd.auc.dk (Lars Peter Fischer)
Subject: Re: Questions about token merging and trigraphs
Organization: Mathematics and Computer Science, Aalborg University
Date: Mon, 21 Dec 1992 21:22:14 GMT


>>>>> "Kevin" == Kevin D. Quitt (kdq@quest.UUCP)

Kevin> for L i=0; i<max; i++ M J
Kevin>    aNiO = i;
Kevin> K

Well, ( and ) are not part of the problematic set, but never mind.

As someone who has had to program on systems that used wierd
characters in place of {}[] I'd say that it's not that much of a
problem. Remember, the characters that replace {}[] are not used
anywhere else, so you quickly adapt.

I'd much prefer using those symbols instead of trigraphs. At least
that would save me from a lot of trouble when I replace the old
equipment :-)

/Lars
--
Lars Fischer, fischer@iesd.auc.dk | It takes an uncommon mind to think of
CS Dept., Aalborg Univ., DENMARK. | these things.  -- Calvin
Newsgroups: comp.lang.c
From: ctoth@magnus.acs.ohio-state.edu (Christopher M Toth)
Subject: Running programs in Borland C++ for Win
Organization: The Ohio State University
Date: Thu, 31 Dec 1992 21:52:50 GMT


	Does anyone know how to execute programs in Borland C++ for windows?
I just got it and *can* run a program, but cannot read the data that is 
generated by the program. When I was using Unix, I just hit the EOF key to
stop my C programs( and the data was displayed after the EOF key was hit). I
can deactivate my C programs by hitting alt-C or alt-break, but that doesn't
display anything. ANy help?

Thanks,

-- 
Christopher M. Toth             | "... We travel in the dark of a new moon
The Ohio State University       | A starry highway traced on the map of the sky
Columbus State                  | Like lovers and heroes,
CIS/History/Classics/ect..Major | Lonely as the eagle's cry..." -Peart
From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
Newsgroups: comp.lang.c
Subject: Re: Problems freeing memory using "free"
Keywords: malloc,free,panic.
Date: 21 Dec 92 17:15:23 GMT
Organization: McGill Research Centre for Intelligent Machines

In article <BzH3uB.KnI@ccu.umanitoba.ca>, ies@access.mbnet.mb.ca (Integrated Engineering Software) writes:

> When is dynamically allotted memory using c(m)alloc freed after
> calling "free"?

By the time free returns, the memory has been freed and must not be
accessed again.  Most implementations will permit the memory to
continue to exist for some indeterminate time after free() returns;
some will even leave the former contents undisturbed for a while.  You
cannot depend on either of these.

> Using os_view() on a SGI, I am able to monitor the RAM available
> before a call to c(m)alloc and after a call to free().  The OS
> indicates that the dynamic memory has been allotted from the
> available RAM(a test problem) and but then does not release the
> allotted memory even after a call to free.

This makes it an OS question, and as such it really belongs in the
appropriate OS-specific group, comp.sys.sgi or some such.

Most UNIXish systems' implementations of malloc never return memory to
the OS; memory being free simply means that it is available for further
calls to malloc.  Whether another call to malloc will allocate some or
all of the same memory is implementation-dependent and cannot be
counted upon either way.

> The available RAM is critical for my app, but future malloc's will
> allot memory from the swap space which I do not want to access.

I'm not sure what the problem is here.  If you allocated a block and
freed it, and future mallocs don't return it, the system will push
those pages to swap because you're not accessing them, thus letting you
keep something else in-core instead.  If future mallocs do return that
same memory, no problem.

					der Mouse

			    mouse@larry.mcrcim.mcgill.edu
Newsgroups: comp.lang.c
From: ah017@yfn.ysu.edu (John B. Lee)
Subject: Arrays with variable dimensions?
Organization: Youngstown State University/Youngstown Free-Net
Date: Sat, 26 Dec 1992 22:07:36 GMT


Is it possible to create an array that would change size according
to user input?

John Lee
usr7245a@cbos.uc.edu
ah017@yfn.ysu.edu
-- 
Xref: sparky comp.lang.c:18850 comp.unix.bsd:10611
From: mark@alsvid.une.edu.au (Mark Garrett Internet: mark@arvak.une.edu.au Phone: +61 66 20 3859)
Newsgroups: comp.lang.c,comp.unix.bsd
Subject: Re: Segmentation faults
Date: 24 Dec 92 03:30:45 GMT
Organization: University of New England - Northern Rivers (Lismore)

From article <BzGHo4.AK9@fs7.ece.cmu.edu>, by woyansky@flamingo.ece.cmu.edu (George J. Woyansky):
> 
> |> 
> |> 
> |> Hi,
> |>     Why is the following code producing a segmentation fault???
> |> I am compiling this code on an Encore Multimax running UMAX 4.3 Unix.
> |> Please send replies to CBUSCH@ub.d.umn.edu.
> |> 
> [OK frags deleted] 
> |> 
> |> void writexy(x,y,s)
> |> {
> |>    printf("\33[%d;%dH%s",y,x,s);
> |> }
> |>    
> 
> 
> 
> Hmm.  Maybe here?  You need 
> int x,y;
> char s[];
> 
> after your function declaration.

	That is correct the c compiler will have assumed x , y and s to be 
signed integers, thus incorrectly using s.

	Cheers
		Mark :)
-- 
Mark Garrett	Internet:  mark@arvak.une.edu.au	Phone: 	+61 66 20 3859
   University of New England, Northern Rivers, Lismore NSW Australia.
Newsgroups: comp.lang.c
From: dkeisen@leland.Stanford.EDU (Dave Eisen)
Subject: Re: Function definition style
Organization: Sequoia Peripherals, Inc.
Date: Thu, 31 Dec 92 05:43:59 GMT

>>I try to use the style in ansi k&r, but I notice that others are using this
>>style and I assume they aren't all using pre-ansi compilers.
>
>IMHO, one should be *very* careful in picking up coding habits from other
>programmers.  Often a programmer will use a particular feature or style
>out of laziness or ignorance of superior alternatives.

Or for other perfectly valid reasons like portability. There
are still a fair number of folks left who use compilers that
don't understand prototypes.

But Dave's point is valid. You shouldn't use a particular style
just because other programmers use it --- their needs may be 
different from yours so they may have chosen their style for
reasons that don't apply to you. In this case, using prototypes
is such a big win over using C Classic function definitions that
unless portability to pre-ANSI compilers is a major design goal
of your project, you should use the ANSI style of function
definition.



-- 
Dave Eisen                               Sequoia Peripherals: (415) 967-5644
dkeisen@leland.Stanford.EDU              Home:                (415) 321-5154
       There's something in my library to offend everybody. 
          --- Washington Coalition Against Censorship
From: adcrumpler@npe.isnet.inmos.co.uk
Newsgroups: comp.lang.c
Subject: Any hope for me..?
Date: 2 Jan 93 21:55:28 GMT
Organization: Inmos Limited
Nntp-Posting-User: adcrumpler

Hello to everyone....


From reading the questions and their corresponding replies
in this newsgroup, I have come to the conclusion that
the majority of people contributing to this newsgroup are
pretty clever dudes ! 

What I'd like to know is:-  What range of academic qualifications
do the various contributors possess ?  And can I, who didnt really
make the most of his schooldays, hope to attain similar levels
of knowledge and competence as you all possess ?

I guess this may not be the right type of question for this particular
group but my knowledge of NEWS is extremely limited, as is the variety
of groups I can access...

Thanks v much !

Stan The Man. 
Newsgroups: comp.lang.c
From: niko@iastate.edu (Nikolaus E Schuessler)
Subject: Re: Yacc/ BNF Form / HELP!
Organization: Iowa State University, Ames, IA
Date: Mon, 28 Dec 1992 17:47:32 GMT




>
>I find that Holub's book complements the Dragon Book nicely and 
>is superior when what you require is a quick example.

Is this the 'Dragon Book'?

>>Buy "Compilers: Principles, Techniques, and Tools" by Aho, Sethi, and Ullman.




-- 
Niko Schuessler               
Project Vincent Systems Manager              email: niko@iastate.edu
Iowa State University Computation Center     voice: (515) 294-1672
Ames IA 50010                                snail: 272 Durham
From: jna@silver.lcs.mit.edu (this is where it all begins)
Newsgroups: comp.lang.c
Subject: Yacc/ BNF Form / HELP!
Date: 27 Dec 92 06:36:59 GMT
Article-I.D.: mintaka.1992Dec27.063659.5238
Organization: We Take What We Want, Inc.

Hi there... I'm looking for information / help on writing a parser. Unix MAN
pages drive me straight up the wall, and I'd like to be able to create a
parser for a simple graphics system with about 15 or so commands..


How does Lex work?
How do I use lex and yacc to make a parser?
How do I write in BNF form?

thanks in advance; please email replies.
-john
From: adrian@romulus.rutgers.edu (Adrian Rodriguez)
Newsgroups: comp.lang.c
Subject: Re: Yacc/ BNF Form / HELP!
Date: 27 Dec 92 19:34:24 GMT
Organization: Rutgers Univ., New Brunswick, N.J.
Cc: adrian

Buy "Compilers: Principles, Techniques, and Tools" by Aho, Sethi, and Ullman.

Read it.
Learn it.
Live it.


Regards,

adrian


PS:  I wouldn't say that this book is difficult reading, but it is perhaps not
     for beginners.  You'll need some experience with data structures to
     appreciate it.
Newsgroups: comp.lang.c
From: leus@aix.rpi.edu (Sheua-Wan Leu)
Subject: fgetc problem
Keywords: fgetc
Date: Tue, 29 Dec 1992 21:27:40 GMT


I want the following program to read data from an input.pts file.For the
first 4 sets data, it works fine, but it print out the last data twice.
If I delete the first line in input.pts file(content 1), it program does
not work at all.

Is there anyone can give me some sort of hint ? Except the fgetc, is there
other function I can use ?

Sheua-wan @rpi
/************************* program *******************************/

#include <stdio.h>
#include <stdlib.h>
struct node{
	int id;
	int x;
	int y;
	struct node *next;
};
typedef struct node NODE;

void get();
void newnode();
NODE *head;
main()
{
	NODE input;
	
	FILE *ifp;
	int c;
	int i,xx;

	head=NULL;
	ifp=fopen("input.pts","r");
	while((c=fgetc(ifp)) !=EOF){
	fscanf(ifp,"%d %d %d",&input.id, &input.x,&input.y);
	printf("num\n");
	newnode(input);
	}
	for(i=0;i<10;i++){
	printf("input search node :");
	printf("\n");
	scanf("%d",&xx);
	get(xx);
	}
}
void newnode(NODE data)
{
	NODE *temp;
	temp=(NODE *)malloc(sizeof(NODE));
	temp->x=data.x;
	temp->y=data.y;
	temp->id=data.id;
	if(head==NULL)
	  {
	   temp->next=NULL;
	   head=temp;
	  }
	else
	  {
	   temp->next=head;
	   head=temp;
	}
}

void get(int find)
{
	NODE *first,*curr;
	first=head;
	for(curr=first;curr !=NULL; curr=curr->next)
	     if(curr->id==find)
	     printf("got it out=%d %d %d\n",curr->id,curr->x,curr->y);
}
/************************* data file ***************/	
1
1  100 	250
2  50 	10
3  50 	50
4  1  	100
5  2	300
From: misar@rbg.informatik.th-darmstadt.de (walter misar)
Newsgroups: comp.lang.c
Subject: Re: Need help with string arrays
Date: 30 Dec 92 15:56:48 GMT
Organization: TH Darmstadt

In article <1992Dec27.232512.22474@news.ysu.edu>, ah017@yfn.ysu.edu (John B. Lee) writes:
> 
> In a current program that I am writing I have an array declaration
> that looks like this:
> 
> char names[][4];

This would be an array of strings, all 4 chars long.
 
> How would I use the gets() function to put a string into this array.
> Am I declaring the array correctly to receive five strings?  << This
> is what I'm trying to do.

You could declare names as char *names[5], but then you had to provide
storage for the strings yourselve (e.g. via malloc). An alternative would be :
#define LEN 32
char names[5][LEN];
.....
fgets(name[i],LEN,stdin)  /* ensuring that no more than LEN bytes are read */
......

-- 
Walter Misar                        It is impossible to enjoy idling thoroughly
misar@rbg.informatik.th-darmstadt.de       unless one has plenty of work to do.
Newsgroups: comp.lang.c