HDTenEightyP/NetNews huggingface dataset:
From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
Newsgroups: comp.lang.c
Subject: Re: malloc() as a user defined function
Date: 12 Oct 92 07:53:49 GMT
Followup-To: comp.lang.c
Organization: Comp Sci, RMIT, Melbourne, Australia

In article <Bvv6pH.Gzy@cs.psu.edu>, ytang@red.crayola.cs.psu.edu (Yuan-Ling Tang) writes:
>     In programming on dynamic memory allocation, I prefer doing check on
>     every malloc(). I.e.:
Good

>     if ((p=(SOME_TYPE *)malloc(sizeof(SOME_TYPE))) == NULL) {
> 	printf("Malloc error.\n");
> 	exit(0);
>     }

Bad.
(1) Standard output might be routed to a file.
    Use stderr, which is there precisely for you to write error messages.
(2) 0 indicates to the caller that the program WORKED.  If you have ANSI
    headers, <stdlib.h> defines
	EXIT_SUCCESS		-- give to exit() to indicate success
	EXIT_FAILURE		-- give to exit() to indicate failure
    So the portable way to do this is
	exit(EXIT_FAILURE);
    If you haven't got ANSI headers, use 1.  (Note:  don't _ever_ use
	exit(-1);
    In UNIX, exit codes are truncated to _unsigned_char_.
    In DOS, if I can trust my Turbo Pascal book, exit codes are the
    equivalent of unsigned short.

So:
	if ((p = (SOME_TYPE *)malloc(sizeof *p)) == NULL) {
	    fprintf(stderr, "Unable to allocate enough memory.\n");
	    exit(EXIT_FAILURE);
	}

>     It turned out it's a pain to type in the above four lines if I have 
>     lots of malloc() invocations in the program, also, the program looks
>     ugly. So I tried to use a function called my_malloc():
> 
>     SOME_TYPE *my_malloc()
>     {
> 	SOME_TYPE *p;
> 
>         if ((p=(SOME_TYPE *)malloc(sizeof(SOME_TYPE))) == NULL) {
>     	    printf("Malloc error.\n");
> 	    exit(0);
>         }
> 	return(p);
>     }

Just imitate malloc.  The usual method is

	void *emalloc(size_t size)
	    {
		void *result = malloc(size);
		
		if (result == NULL) {
		    fprintf(stderr, "Unable to allocate enough memory.\n");
		    exit(EXIT_FAILURE);
		}
		return result;
	    }

Then call it just like malloc():

	    p = emalloc(sizeof *p);

In a "Classic C" compiler you will need to use char* rather than void*
and you will need a cast every time you use emalloc(), just like malloc().

The general rule in C is that you _can't_ pass a type to a function, 
but you _can_ pass sizeof (type) to a function.
From: R2NVK@VM1.CC.UAKRON.EDU
Newsgroups: comp.lang.c
Subject: Iterative Consensus method
Date: 9 Oct 92 00:18:36 GMT
Article-I.D.: VM1.1687A11D9C.R2NVK
Organization: The University of Akron

Hi,
  I am looking for the source code for Iterative Consensus Method(minimizes a t
ruth table, removing all redundant terms). It will be really helpful if anyone
could give any pointers where to find it or send me the code. Thanking you in
advance.
         nagesh
From: d07060@rs6000_1.dir.co.jp (Masanori Kinouchi)
Newsgroups: comp.lang.c
Subject: Re: Scanf and pointer problem, HEELP!!
Date: 14 Oct 92 01:48:43 GMT
Organization: Daiwa Institute of Research Ltd., Tokyo

"char *file_name;" allocates a (probably 4-byte) pointer to a string,
not the buffer for the string. You should write, instead,

    #define MaxFilenameSize 32
    char file_name[MaxFilenameSize];
or
    #define MaxFilenameSize 32
    char *file_name;
    file_name = (char *)malloc(MaxFilenameSize);

Then you can scanf file_name whose length is shorter than MaxFilenameSize.

-------
When the compiler sees the line 

char *file_name = "";

it prepares a null string and sets up "file_name" to point the 
null string. If you carry out "scanf("%s",file_name);" in this
situation, scanf will reads a string into the buffer the compiler
prepared for the null string. The length of the string scanf reads
is usually longer than that of the null string (which is one), so
you might have broken something else. Anyway, you replaced the 
content of the buffer the compiler believes to be a null string.

Seeing the line

char *nodename = "";

the compiler doesn't prepare a NEW null string. It knows it has
prepared one before, and sets up "nodename" to point it. Now you
see what is happening. What the compiler believes to be a null 
string is no longer a null string. 

Hope this helped you.
--Masanori
Newsgroups: comp.lang.c
From: bubeck@peanuts.informatik.uni-tuebingen.de (Till Bubeck)
Subject: Re: question about duplicate declarations
Organization: "Lehrstuhl fuer Technische Informatik, Uni Tuebingen"
Date: Fri, 16 Oct 92 12:52:34 GMT

I think it should result in an error message...But no one's interested in my
opinion...
   
Newsgroups: comp.lang.c
From: drice@ponder.csci.unt.edu (Keith Rice)
Subject: Re: What is RPG ???
Organization: University of North Texas
Distribution: na
Date: Wed, 7 Oct 1992 23:12:49 GMT

In <1992Oct3.052108.14157@mnemosyne.cs.du.edu> amwalker@nyx.cs.du.edu (Art Walker) writes:

>silvia@rcf.rsmas.miami.edu writes:

>>In article <1992Oct2.015817.183@wsuhub.uc.twsu.edu>, ckcheng@wsuhub.uc.twsu.edu writes:
>>>     Hey, does anybody heard of RPG (language or system?, NOT role playing game
>>>) ?  Can anyone talk about it in this category or open a new category ?
>>RPG stands for Report Program Generator. It is usually found on minis and
>>mainframes. It is a language that requires inline coding. A real headache.

>To be more specific, RPG is almost exclusive to IBM minicomputers (what they
>like to call "midrange" systems) such as the System/36, System/38, and AS/400.

It's not almost exclusive to minis.  I learned RPG on an IBM 4381 running
VSE and know of many IBM shops that use, or used, RPG.

--
_____________________________
__-----____--___--__-----____	D. Keith Rice
__--__--___--__--___--__--___	University of North Texas
__--___--__--_--____--___--__	Department of Computer Science
__--___--__----_____--__--___	Denton, Texas, USA
__--___--__--_--____--_--____
__--__--___--__--___--__--___	drice@ponder.csci.unt.edu
__-----____--___--__--___--__
_____________________________
From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.lang.c
Subject: Re: Strings and integer sizes
Date: 12 Oct 92 22:01:54 GMT
Organization: negligable

In article <1992Oct9.075710.13377@klaava.Helsinki.FI> wirzeniu@klaava.Helsinki.FI (Lars Wirzenius) writes:
>hartman@ulogic.UUCP (Richard M. Hartman) writes:
>>I have this in a central include file as:
>>	strncpyz(d,s,n) { strcpy(d,s,n); d[n] = '\0'; }
>
>Is n the size of the destination or the maximum length of the target
>string, i.e. destination size - 1 ?  If the former, then the last
>assignment should be d[n-1]='\0', of course.

We have been using it as the maximum number of characters to be
copied from s to d, it is up to the programmer to ensure that the 
destination has the room for the additional nul byte.  It is meant 
to be a drop-in replacement for strcpy() which takes the # of characters
to be copied, which is not necessarily the size of the destination.

Given your correction that would imply that the last char
copied by strcpy() would be overwritten, which would have been
equivilant to passing "n-1" to strcpy(), which would make the 
intent obscure to say the least.

In other words, if I have

	char buf1[81] = "Hello, world\n";
	char buf2[81];

I want:

	strncpyz(buf2, buf1, 5);

to give me "Hello\0" in buf2.  Note that sizeof(buf2) would have
been entirely inappropriate since buf2 is just a generic line-sized
buffer.

>>I think there's a memcpyz() to go w/ memcpy(), but I'm not sure....
>
>Seems curious, since the mem* functions shouldn't care about null
>characters.

You're probably right.  I said I wasn't sure.

>By the way, if you follow strict ANSI rules, your function names (if
>they are of external linkage) are not quite valid, since names with
>external linkage and beginning with mem and a a lowercase letter, or str
>and a lowercase letter are reserved, i.e. should not be used by the
>programmer, only the C library implementor.  (If you are implementing a
>library, the issue is fuzzier.)

This is in a library meant for internal in our company.  Actually
strncpyz() is implemented as a #define, which is perhaps worse for 
what it's worth....



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
If only you knew what's inside of me now	|
you wouldn't want to know me, somehow.		|	-Richard Hartman	
But, you will love me tonight,			|	hartman@uLogic.COM
we alone will be all right.  Heaven!		|
From: barmar@think.com (Barry Margolin)
Newsgroups: comp.lang.c
Subject: Re: Are pointer just addresses???
Date: 13 Oct 1992 23:11:19 GMT
Organization: Thinking Machines Corporation, Cambridge MA, USA
NNTP-Posting-Host: telecaster.think.com

In article <1992Oct12.232801.19149@julian.uwo.ca> choi4@gaul.csd.uwo.ca (Wai Kin Choi) writes:
>  "Are pointers just addresses of memory?"

Sometimes yes, sometimes no.  On systems with traditional, flat address
spaces, pointers are usually just addresses.  On 80*86 systems in some
memory models, pointers are offsets into a designated data or code segment
(depending on whether they're data or function pointers).  On Symbolics
Lisp Machines, pointers are a combination of an array reference and an
offset.
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

barmar@think.com          {uunet,harvard}!think!barmar
Newsgroups: comp.lang.c
From: hermann@uran.informatik.uni-bonn.de (Hermann Stamm)
Subject: RE: line number in C program
Reply-To: hermann@uran.informatik.uni-bonn.de (Hermann Stamm)
Organization: Praktische Informatik III
Date: Wed, 7 Oct 1992 11:19:14 GMT

In article <1992Oct5.193542.11024@cs.brown.edu> you write:
|> 
|> Is there a way for me to find out what line number is currently being
|> executed in a c program from within that program?
|> 
|> Will this method also work in C++?
|> 
|> Harry.
|> 
|> hm@cs.brown.edu

As mentioned earlier a solution is the use of __LINE__.

Below you find a shell-script, which automatically replaces a @
at the end of the line by the string "printf("%d\n",__LINE__);",
and then compiles the modified program. The first argument to
the script (with or without .c) will be used, temporal files are
deleted. replace "acc" by "gcc" if you use the gnu-compiler.

This means:

...
  int i;
  i=5;@
...

is transformed to

...
  int i;
i=5; printf("%d\n",__LINE__);
...

and then compiled.

--------------------------------------------------------------------------------------------------------------------------
awk ' ( substr($0,length,1)=="@" ) { printf("%s",substr($1,1,length-3)); printf("printf(%c%%d\\n%c,__LINE__);\n",34,34);} (substr($0,length,1)!="@") { print }' $1 >$1.awk.c; (acc $1.awk.c; rm $1.awk.c)
--------------------------------------------------------------------------------------------------------------------------

(note, the above is one line)


Hope this helps,

   Hermann.

Newsgroups: comp.lang.c
From: chupchup@ferkel.ucsb.edu (Robert Earl)
Subject: Re: Question about fread() and fwrite()!
Organization: (EVIL!)
Date: Fri, 16 Oct 1992 09:12:54 GMT

ren@miles.mps.ohio-state.edu (Liming Ren) writes:

| I write a short program to test fread() and fwrite(), I don't get what I want and I can't figure out why. Please help.

|   ptr=fopen("data2", "wr");
|   fseek(ptr, 0L, 0);
|   p=&temp;
|   fwrite(p, sizeof(wr), 1, ptr);
|   p=&temp2;
|   fread(p, sizeof(wr), 1, ptr);
|   fclose(ptr);

Your fread() and fwrite() look fine, but you need to fseek() in
between them!  Otherwise the file pointer is sitting beyond the record
you just wrote.  Also, I don't believe "wr" is a valid mode for
fopen().  Try "w+" or "a+" for append mode.

| Another question is: Is the size of a structure the summation of all
| the size of its elements? If not, any formula for it beside using
| sizeof()?

Yes, it is the sum of all the elements' sizes.

-- 
robert earl          |
rearl@ucsd.edu       | "I got a bottle of tequila, baby, who needs friends?"
rearl@piggy.ucsb.edu |   --Johnette Napolitano, Concrete Blonde
From: fcaggian@rentec.com (Frank Caggiano)
Newsgroups: comp.lang.c
Subject: Re: ### Question about setitimer ####
Date: 9 Oct 92 13:44:58 GMT
Distribution: usa
Organization: Renaissance Technologies Corp., Setauket, NY.

In article <1992Oct7.191250.2587@aa.cad.slb.com> conniff@mailhost.aa.cad.slb.com (Steven D. Conniff) writes:

>I am having some difficulties with using setitimer.  Here is my program:

	[ program lines deleted ]

>    value.it_interval.tv_sec = 0;
>    value.it_interval.tv_usec = atol(argv[1]);

>    setitimer(ITIMER_REAL, &value, &ovalue);
>    pause();

You have never set the timer value (it_value) only the interval (it_interval).
The value in it_value specifies the time to the next expiration of the timer. 
You set this yourself the first time and then it is reloaded after the timer 
expires from the value you placed in it_interval.  If it_interval is 0 then
the timer is disabled after the first alarm.  At anytime you can set it_value
to 0 to disable the timer.

-- 
------------------------------------------------------------------
	`The sensibility of man to trifles, and his insensibility
to great things, indicates a strange inversion.'
					Blaise Pascal

Frank Caggiano                      INTERNET: fcaggian@rentec.com  
Renaissance Technologies Corp.      UUCP: ..!uupsi!kepler1!fcaggian
100 North Country Rd.                    fax: (516) 246-5761
Sekauket, NY 11733                     voice: (516) 246-5550
Xref: sparky comp.lang.c:14797 alt.folklore.computers:14998
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.lang.c,alt.folklore.computers
Subject: Re: What is RPG ???
Date: 11 Oct 92 06:05:24 GMT
Reply-To: dave@cs.arizona.edu (Dave Schaumann)
Distribution: na
Organization: University of Arizona

I had a friend (who was obliged to program in it) that told me that
RPG stands for

	Rotten Pile of Garbage.

I decided then & there that that's all I really needed to know.

-- 
--- jumbo shrimp --- pretty ugly --- awfully nice --- constant change ---
Newsgroups: comp.lang.c
From: chambles@whale.st.usm.edu (John William Chambless)
Subject: Re: Problem with TC 2.0
Organization: University of Southern Mississippi
Date: Fri, 16 Oct 1992 02:43:28 GMT

 

In article <1992Oct16.003104.11323@qualcomm.com> gbrand@qualcom.qualcomm.com (Graham Brand) writes:
>A simple question for the Turbo C wizards out there. I have a TC2.0
>program which gives me a strange error. On compiling with the
>default options, the linker gives me a strange error:
>   _main not found in module C0S
>or words to that effect. What is the cause and how do I fix it?
Just by coincidence: this happened to me today!
Check and make sure that your source file has a main() function.
:) Now don't you feel silly?   :)

-- 
* Billy Chambless   University of Southern Mississippi, USA
* Opinions expressed are no sillier than yours...
* "As you become a more powerful and subtle programmer,
* your mistakes will become more powerful and subtle" 
* -from the Waite Group's New C Primer Plus
Newsgroups: comp.lang.c,comp.programming
From: msb@sq.sq.com (Mark Brader)
Subject: Skip lists (was: Speeding up linked lists)
Followup-To: comp.programming
Organization: SoftQuad Inc., Toronto, Canada
Date: Wed, 14 Oct 92 05:02:30 GMT

Dave Schaumann (dave@cs.arizona.edu) answers a question in comp.lang.c:

> > How else can one speed up linked list lookups?
> 
> Use a different data structure.  Hash tables, tries, binary search trees,
> stacks and queues are all useful modifications on the basic linked-list
> structure, and each has its own strengths and weaknesses.

To this bag of tools should be added the skip list, which was invented
by William Pugh in 1987 and described by him in the June 1990 issue of
Communications of the ACM.  They have also been described by Frederick
Hegeman in the February 1991 issue of the C Users Journal.

The basic idea is that you want to maintain an ordered list, with extra
links in, say, every 4th node that will point to only the nodes in that
sublist.  (As a railfan, it occurs to me to think of the original and
extra links as locals and expresses...)  But this continues: another
set of extra links connects every 16th node, another set every 64th, and
so on for as many levels as you think worthwhile.

But, you say, when you're building the list you *don't know* which nodes
will ultimately be "every 4th" or "every 16th", so how can you decide
which ones get the extra links?  Well, here's the key trick -- you don't
worry about placing them exactly.  Any reasonable approximation will do.
So, when you're about to insert a new node, you call a *random number*
generator, and decide with a with a *probability* of 1/4, 1/16, ... to
insert or not insert the extra pointers for that node!  The longer the
list, the better the random variations are likely to cancel out; the
shorter the list, the less they are likely to matter.

I specified a factor of 4 at each level in the above discussion for the
sake of concreteness, but any reasonable factor can be used instead.

I have no great knowledge of skip lists -- I only heard of them for the
first time a few days ago -- but I can recognize a valuable technique
when I see it.  And as the man who pointed me at the articles said, a
lot of us have not heard of the technique because it is simply too new.
So I thought it a good idea to mention it here.  As with all the other
methods mentioned above, it has its own advantages and disadvantages;
discussion on these should be in comp.programming, to which I have
directed followups.

For more details on skip lists, with diagrams and sample C code, see
the Hegeman article.  I haven't read Pugh's article, but would expect
a more thorough algorithmic analysis there since it's in CACM.

> Since it's often difficult to know which will be best before you start
> working on the program, it's best to write your code so that if you
> decide later that you've chosen wrong, you can simply take out the
> code for one and plug in the code for another.

Hear, hear!
-- 
Mark Brader, SoftQuad Inc., Toronto		"Tools, not solutions. :-)"
utzoo!sq!msb, msb@sq.com				    -- Henry Spencer

This article is in the public domain.
Newsgroups: comp.lang.c
From: u8800914@cs.uow.edu.au (Mohammad Salim Olime)
Subject: HELP:PROBLEM with TCXL
Summary: Cannot compile tcxldemo.c
Keywords: TCXL
Organization: Dept of Computer Science, Wollongong University, Australia
Date: Wed, 7 Oct 1992 07:07:16 GMT

I have down loaded TCXL from simtel-20 archie. I followed the instruction
provided in the accompanied documentation correctly(Hopefully).
But can't compile/link the sample demo program provided. I mean tcxldemo.c.
the compiler complains that it can't include _TCXLvid.h . And unfortunately
the above mentioned header file is missing from INC directory provided.
To be more specific I am using Turbo C version of TCXL and have set the
environment variables TCXL_A and TCXL_C.
Any help or hint is most appreciated.
Newsgroups: comp.lang.c
From: jes@grendel.demon.co.uk (Jim Segrave)
ReplyTo: jes@grendel.demon.co.uk
Subject: Re: Strings and integer sizes
Distribution: world
X-Mailer: cppnews $Revision: 1.18 $
Organization: None
Date: Fri, 9 Oct 1992 21:29:48 +0000


In article <1992Oct9.125347.24160@blaze.cs.jhu.edu> wilson@rhombus.cs.jhu.edu (Dwight Wilson) writes:

> >>:literal, optionally enclosed in braces. Successive characters of the
> >>:character string literal (including the terminating null character
> >                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >>:if there is room or if the array is of unknown size) initialize the
> >  ^^^^^^^^^^^^^^^^
> >>:elements of the array.'
> >
> >The initialization
> >
> >	char zoe[3] = "abc";
> >
> 
> Does anyone know what the rationale was for accepting this form?
> It's won't necessarily work on pre-ANSI compilers (in fact
> I expect it would break on most of them) so the excuse of 
> maintaining compatibility with old code doesn't apply.  It
> is likely to cause confusion and errors, just wait until someone
> tries to pass it to one of the str* functions.  
> 
> This initialization is illegal in C++ (though at least one of
> the compilers I use doesn't even give a warning :-(), and IMHO
> it was a mistake to allow this in C.  Any comments?
> 
> -Dwight

At a guess, it gives you a way of initialising character arrays
which may not use a trailing zero convention. Consider a disc directory
entry -
struct dir_entry {
        unsigned short i_node_number;
        char           file_name[14];
};
Now if you want to pre-cook a directory, how do you set up the name
'fourteenlong'?
an initialiser of:
struct dir_entry florence = { 2, {'f', 'o', 'u', ... 'r'}};
is horrible to read - I'm too lazy to even type the whole thing out.
whereas:
struct dir_entry florence = { 2, "fourteenchar"};
is not so bad. The compiler will complain if you make it too long, and,
if it's only "xivchar", it will pad it out with zeros for you.
 
--
Jim Segrave (Segrave Software Services)     jes@grendel.demon.co.uk

Newsgroups: comp.lang.c,comp.lang.c++,comp.lang.pascal,comp.ai.neural-nets
From: vannes@srzts304.alcatel.ch (Tom van Nes)
Subject: pattern classification / template maching
Reply-To: thomas.vannes@alcatel.ch
Organization: Alcatel STR AG Switzerland
Date: Thu, 15 Oct 1992 16:52:28 GMT

I'm looking for a piece of code in c or pascal to do the following:

In our firm we have all kinds of parts needed in manufacturing
that have names which differ slightly. These parts are to be
classified. The idea is to be able to enter a fragment of a name
into a program which then gives me list of part names or groups
to further narrow down my choice. I don't want to build a giant
database with all possible names, I only need a smart
algorithem, C-code working with strings, or some neural application
for the problem. The problem reminds me of a tesaurus such as
in word prcessing programs, but they use large databases.


-- 
+----------V----------+  Tom van Nes        |RFC822: thomas.vannes@alcatel.ch
| A  L  C  A  T  E  L |  Alcatel STR        |DECnet: PSI%4795123920::T_VANNES
+---------------------+  Friesenbergstr. 75 |X.400:  c=CH a=arCom p=Alcatel
         S T R           CH-8055 Zuerich    |        s=Vannes g=Thomas
Newsgroups: comp.lang.c
From: wieck@jwminhh.hanse.de (Jan Wieck)
Subject: Re: TC++ 1.0 spawn() question.
Organization: Private Site under Mach386
Date: Mon, 12 Oct 1992 21:38:09 GMT

From article <nhu1H8ug2a@atlantis.psu.edu>, by newton@wilbur.psu.edu (Cynthia Newton):
> 
> [...]
> 
> spawnvp(P_WAIT,"test.exe",NULL); <-works if the location is in PATH
> spawnvp(P_WAIT,"C:\TEST\TEST.EXE",NULL) <-does not work, perror says
		    ^^
		    ||

This is a single 'T'. You just quoted it. Better write
... "C:\\TEST\\TEST.EXE" ... to get what you want.


Until later, Jan


-- 
# Any language keeps its own misunderstandings; #
# why shouldn't programming languages do?       #
#                                               #
#            wieck@jwminhh.hanse.de (Jan Wieck) #
Newsgroups: comp.lang.c
From: wieck@jwminhh.hanse.de (Jan Wieck)
Subject: Re: Who is using a file?
Organization: Private Site under Mach386
Date: Mon, 12 Oct 1992 21:46:26 GMT

From article <67527@cup.portal.com>, by Dave-Nuttall@cup.portal.com (David Dave Nuttall):
> Is it possible for a C program running on a System V 3.2 UNIX box
> to determine if any current user is accessing a particular file,
> (or device)?

Like the usage of memory and cpu, open files are registered in a kernel's
table. If you can locate its address (look into the kernel's name table),
you can examine it with a program similar to the ps-command. 


Until later, Jan


-- 
# Any language keeps its own misunderstandings; #
# why shouldn't programming languages do?       #
#                                               #
#            wieck@jwminhh.hanse.de (Jan Wieck) #
Newsgroups: comp.lang.c