HDTenEightyP/NetNews huggingface dataset:
From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
Newsgroups: comp.lang.c,comp.programming
Subject: Re: A LITTLE BRAINTEASER...
Date: 12 Aug 92 15:42:49 GMT
Organization: Computer Science, University of Melbourne, Australia

s1110238@giaeb.cc.monash.edu.au (Lee Hollingworth) writes:

>aet@mullian.ee.mu.OZ.AU (bert thompson) writes:
>
>>my question is this:
>
>>is it possible to write a program that reverse the order of input lines
>>without using data structures.
>
>>the
>>quick
>>brown
>
>>becomes:
>
>>brown
>>quick
>>the
>
>>the rules of the game are you can use anything but data structures, or more
>>specifically you cannot use the heap.
>>i think it can be done, but i can't figure out how.
>>(use of a few mutually recursive functions i think is the go.)
>
>>anyone got an idea??
>
>#include <stdio.h>
>
>void main(void)
>{
>    char str[81];
>
>    if (!*gets(str)) {
>        return;
>    }
>    else {
>        main();
>        puts(str);
>    }
>}
>
>The above uses one local variable like your previous example..., but maybe
>this is not what you meant.
>
>Lee Hollingworth

Yes, but it doesn't work for lines longer than 80 characters.

Also it does use an array, which is a data structure.
Bert wanted to avoid arrays:

>>the interesting thing about the program is that it uses no data structures
>>(structs, arrays, pointers, etc..), to do its thing.

I think that the problem is unsolveable without at least using pointers.
Here's an example that works for arbitrary length lines and uses only
chars and pointers. It's not strictly ANSI-compliant, but it is very portable.

#include <stdio.h>
void rev(int *l,int **p) {
    int c;   
    int *n;  /* look, Ma, no structs or arrays, and no dynamic allocation! */

    *(l?p:&l)=&c; /* I'm practicing for the obfuscated C competition */
    c = getchar();
    if (c == EOF) return;
    if (c == '\n') {
	main();
	n = 0;
        while(l) {
            putchar(*l);
            l=*(int**)((char*)l+((char*)&n-(char*)&c)); /* PUKE! */
        }
    } else {
        rev(l,&n);
    }
}

void main(void) { rev(0,0); }

-- 
Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
This .signature VIRUS is a self-referential statement that is true - but 
you will only be able to consistently believe it if you copy it to your own
.signature file!
Xref: sparky comp.lang.c:12219 comp.programming:2283
From: kpv@ulysses.att.com (Phong Vo)
Newsgroups: comp.lang.c,comp.programming
Subject: Re: A LITTLE BRAINTEASER...
Date: 12 Aug 92 14:40:50 GMT
Organization: AT&T Bell Labs

In article <1992Aug12.103013.4999@cs.ruu.nl> matthys@cs.ruu.nl (Matthys Kuiper) writes:
>In <aet.713608023@munagin> aet@mullian.ee.mu.OZ.AU (bert thompson) writes:
>>is it possible to write a program that reverse the order of input lines
>>without using data structures.
>>the rules of the game are you can use anything but data structures, or more
>>specifically you cannot use the heap.
>
>Below is my solution in Pascal. The translation of this program
>into C is horrible to read and not included in this posting.
<code deleted>

The code probably isn't right either since functions such as readln() may very well
does some form of dynamic memory allocation to store the lines.
Here's a piece of C code that does the job and uses nothing but stack space.
The more general requirement of not using data structures is of course impossible
to satisfy since if a program manipulates data, it has to hold the data somewhere.
The below code uses a thinly disguised link list to store characters of a line.

---------------------------------------------
write_line(line)
char**	line;
{
	if(line)
	{	write_line((char**)line[1]);
		write(1,line[0],1);
	}
}

reverse_lines(last)
char	**last;
{
	char	c;
	char	*line[2];

	if(read(0,&c,1) != 1)
		return;

	if(c != '\n')
	{	line[0] = &c;
		line[1] = (char*)last;
		reverse_lines(line);
	}
	else
	{	reverse_lines((char**)0);
		write_line(last);
		write(1,&c,1);
	}
}

main()
{
	reverse_lines((char**)0);
}
  
Phong Vo, kpv@ulysses.att.com
AT&T Bell Labs, 600 Mountain Ave, Murray Hill, NJ07974
From: c3460344@fsu1.cc.fsu.edu (C3460344)
Newsgroups: comp.lang.c
Subject: Would this be the place to...
Date: 15 Aug 92 12:22:55 GMT
Reply-To: c3460344@fsu1.cc.fsu.edu
Followup-To: ^^^^
Organization: Florida State University
News-Software: VAX/VMS VNEWS 1.3-4

If I have a piece of code that I am having trouble finding a problem in, 
would I post it here?  It is about 50 or so lines...

I am getting garbage in the trans_type element of this structure when I 
print it to screen:

typedef struct {
       char date[9];
       char cknum[4];
       char comment[21];
       char trans_type[4];
       float amount;
} entry;

So, I am assuming that I am lacking some variable initialization.
Please bare with me, I am new to C.  How would I go about initializing an 
array full of these structures (just the trans_type and amount parts, the 
rest is fine)??

-=Jeff Blaine
c3460344@fsu1.cc.fsu.edu
Newsgroups: comp.lang.c,comp.lang.c++
From: martin@oahu.cs.ucla.edu (david l. martin)
Subject: Representing MACROS and header files (?)
Originator: martin@oahu.cs.ucla.edu
Organization: UCLA Computer Science Department
Date: Tue, 18 Aug 92 17:28:27 GMT

I'm involved in a project to "reverse-engineer" C and C++ source code,
so as to be able to produce various reports and graphical views of
existing code, and also possibly to automatically re-structure the
code.  One of the hardest issues is in capturing information about
MACRO definitions and uses.  Another is in capturing information 
about what things are defined in header files, which is problematical
because header files can appear differently depending on which
context they occur in.

More specifically, the challenge is to create a front-end which
saves information about MACROS and header files as distinct things, and 
captures this information in an intermediate representation which has been
extended to include this information in a principled way.

I'd be most interested if anyone has tackled these issues before, and
has ideas and/or information to share.

David L. Martin
Computer Science Dept.
Boelter Hall 3436
U.C.L.A.
Los Angeles, CA 90024-1596
martin@cs.ucla.edu
Newsgroups: comp.lang.c
From: thompson@atlas.socsci.umn.edu (T. Scott Thompson)
Subject: Re: POWER OF LARGE NUMBERS
Organization: University of Minnesota
Date: Thu, 13 Aug 1992 19:33:28 GMT

u8705957@cs.uow.edu.au (Hitesh Sanghvi) writes:

>Hello there;

>	Does any one know how to raise power of possibly 100 digits 
>to possibly 100 digits. Any algorithm or code will be appriciated.

>Example >(1234367463746464647464...up to 100 digit)**(647254627463048736...up to 100 digit)

The order of magnitude of the solution to this problem is 

              10**(10**102)

which is a ridiculously large number.  I would imagine that the number
of significant digits in the answer is of roughly similar magnitude
unless we place some special restrictions on input values.  Is there
any hope of solving this?

What do you netters think?
Newsgroups: comp.lang.c
From: prem@prem.lbl.gov (Shirdi R. Prem)
Subject: Re: Convert float to a string ?
Reply-To: prem@prem.lbl.gov (Shirdi R. Prem)
Organization: Lawrence Berkeley Laboratory
Date: Thu, 20 Aug 1992 22:51:33 GMT

In article <1992Aug20.172112.1564@tin.monsanto.com> bcschu@skws02.monsanto.com (Brett Schultz) writes:
>prem@prem.lbl.gov (Shirdi R. Prem) writes:
>: In article <1992Aug19.204417.13500@tin.monsanto.com> bcschu@skws02.monsanto.com (Brett Schultz) writes:
>: 
>: 	   sprintf(b,"%f\0",a);
>: 		     ^^^^^^
>: 		     ^^^^^^
>: 
>: 	Are you sure you need a '\0' here............???
>: 
>: 	Prem!  (I guess I should've written a test program to find out, )   
>: 	       ( rather than posting this..........                     )

>No, I'm not sure if one NEEDS a \0 there, but it surely doesn't hurt to put
>one there, now you KNOW that your string is null terminated.
>Let me know if sprintf puts one there anyway, I wasn't sure.
>Brett

	Yes. It does.

	-Prem!
From: bsullivn@sc.sni.ie (Bryan O'Sullivan)
Newsgroups: comp.lang.c
Subject: Re: Convert float to a string ?
Date: 21 Aug 92 09:53:01 GMT
Article-I.D.: sc.167
Reply-To: bryan@sc.sni.ie
Organization: Siemens-Nixdorf Software Development Centre, Dublin
X-Newsreader: Tin 1.1 PL3



jaked@well.sf.ca.us (Jake Donham) writes:
>>  float a = 12.34567;
>>  char b[9];
>>
>>  sprintf(b, "%8f");

>uh, make that sprintf(b, "%8f\0", a);, of course.

Why?  You'll overflow your array.  Apart from that trivial reason, the
'\0' you add is of no earthly use.  Don't forget that string literals are
null-terminated by default.

	-- Bryan

-- 
Bryan O'Sullivan                                             +353-1-767551 x225
Siemens-Nixdorf Informationssysteme AG                          bryan@sc.sni.ie
Software Development Centre                    "Theory like mist on eyeglasses.
Dublin                                          Obscure facts." -- Charlie Chan
From: ah739@cleveland.Freenet.Edu (Leslie J. Somos)
Newsgroups: comp.lang.c
Subject: Re: Indian Hill Style Guide
Date: 14 Aug 92 21:24:19 GMT
Reply-To: ah739@cleveland.Freenet.Edu (Leslie J. Somos)
Organization: Case Western Reserve University, Cleveland, OH (USA)


In a previous article, folsom@bigmax.UUCP (Al Folsom) says:

>The FAQ list gives several sites from which to obtain the 
>Indian Hill Style Guide via anonymous ftp.
>
>I do not have anonymous ftp capability.  Does anyone know of 
>an alternative mechanism for obtaining this document, preferably
>in electronic form?

Yes.

>
>Thanks - Al F.
>
>+-------------------------------------------------------------------+
>| Al Folsom                 | Object Oriented Programming?  We've   |
>| Fischer & Porter Co.      | been doing that for years...          |
>| ...uunet!bigmax!folsom    |                                       |
>| also folsom@decus.org     | When the customer objects to the way  |
>| KY3T@WA3TSW (Ham)         | it works, we go program some more!    |
>+-------------------------------------------------------------------+
>
>

OK, just teasing.  
But yes, there is (at least one) way.

Send mail to ftpmail@decwrl.dec.com, with any subject:, with text:
connect <site>
dir <directory name>
get <fully-qualified file name>

For details on how to use ftpmail@decwrl.dec.com, add a text line:
help

I learned about this by reading the groups news.announce
and news.newusers .

Good luck.
Newsgroups: comp.lang.c
From: msb@sq.sq.com (Mark Brader)
Subject: Re: I wish ANSI-C sizeof (void) == 1 (was Re: preprocessing subterfuge)
Summary: Disagree.
Organization: SoftQuad Inc., Toronto, Canada
Date: Tue, 18 Aug 92 14:48:33 GMT

>>> void * is the natural type to use when you're considering a
>>> pointer to a chunk of memory that can hold any arbitrary type ...
>>> And any time I need to do arithmetic on one, it's always in terms
>>> of bytes ...
>> If you need to do arithmetic on one, then the variable should not be
>> declared as "void *" in the first place. That type is for pointing to
>> objects whose size you don't know. ...
> Yes, but I'm _not_ dealing with arrays of bytes. I'm pointing to arbitrary
> locations which store as yet unknown types.

The last two quoted posters are both correct.  In ANSI C, it is specified
that character types occupy one byte and that any object (i.e. a single
declared variable, or the result of a single call to malloc()) is made up
of bytes which can be (sorry, Steve) addressed linearly.  If you really
have to do operations of the type just described, then you ARE viewing the
object as an array of bytes, and char * (or unsigned char *, etc.) is the
right type to use.  If you find this unpleasant, consider "typedef char byte".

Void * points with the same precision as char *, but is appropriate when you
will be treating the object of unknown type as a WHOLE rather than as an
array of bytes.  This is why it has ITS special properties: it can be freely
converted without a cast to and from any other object pointer type, but you
can't do address arithmetic on it.
-- 
Mark Brader			"You can't [compare] computer memory and recall
SoftQuad Inc., Toronto		 with human memory and recall.  It's comparing
utzoo!sq!msb, msb@sq.com	 apples and bicycles."		-- Ed Knowles

This article is in the public domain.
Newsgroups: comp.lang.c
From: tim@shovel.Prime.COM (Tim Cantin)
Subject: Re: turboc help please.
Followup-To: comp.lang.c
Organization: Prime Computer R&D
Date: Wed, 19 Aug 1992 13:33:49 GMT

> I have been running into a memory problem.
> It stops compiling and says out of memory.

I did the same thing when I started coding my first large application.
This is a common problem... try making several source files, and using a
project file (.prj) instead of putting everything in one file (messy). Check
out the manual (or online help) for info on .prj files or 'make' (f9 key).

> How do I change the memory available setting so I can use more of the 4 meg
> of memory?

If there was a way to do it (which I doubt), it would be in the manual.

Good luck,
-T

-- 
#include "stddisclaimer.h"
/* Tim Cantin          {uunet, csnet-relay}!primerd!tim || tim@s35.prime.com
   Prime Computer Inc. 10-21, 500 Old Conn. Path, Framingham, MA 01701 (USA) */
flames > /dev/null 2>&1
Newsgroups: comp.lang.c
From: chuckb@milton.u.washington.edu (Chuck Bass)
Subject: Re: function pointers
Organization: University of Washington
Date: Sun, 23 Aug 1992 01:30:12 GMT

Your approach looks sound.  I use something similar in my
programming.  IE if my function poiner is not NULL I call the
function, (sort of additional parameter handling), If it is NULL
I assume the data is ready to be processed and off I go.

Anyway for me the hardest part was declaring and typedefing the
function pointers correctly.  I found the program cdecl or
c++decl to be of great help.

Later-


Chuck Bass
College of Forest Systems Engineering
University of Washington
chuckb@u.washington.edu
From: volpe@bart.NoSubdomain.NoDomain (Christopher R Volpe)
Newsgroups: comp.lang.c
Subject: Re: I wish ANSI-C sizeof (void) == 1 (was Re: preprocessing subterfuge)
Date: 14 Aug 92 19:51:32 GMT
Reply-To: volpe@ausable.crd.ge.com
Organization: GE Corporate Research & Development

In article <BswME5.6Mp@research.canon.oz.au>, greyham@research.canon.oz.au (Graham Stoney) writes:
|> toriver@flipper.pvv.unit.no (Tor Iver Wilhelmsen) writes:
|> 
|> When I first heard of GNU C's deviation from the standard with the sizeof type
|> 'void', I thought it was a bad idea; but now I hope ANSI will standardise it
|> next time around. void * is the natural type to use when you're considering a
|> pointer to a chunk of memory that can hold any arbitrary type; in the Unix
|> kernel for instance it seems a natural replacement for caddr_t. And any time
|> I need to do arithmetic on one, it's always in terms of bytes - it would be
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you need to do arithmetic on one, then the variable should not be declared
as "void *" in the first place. That type is for pointing to objects whose
size you don't know. If you know you're going to be dealing with arrays of
bytes, then declare it as "[unsigned] char *". 

-Chris

|> great to be able to not have to cast to char * every time you need to do
|> arithmetic on one, which seems to happen quite a lot in stuff like device
|> drivers.
|> 
|> Any comments?
|> 
|> Graham
|> -- 
|> Graham Stoney                    | "a Perl script is correct if it's halfway
|> Flip Dibner fan club, "Hi Flip!" |  readable and gets the job done before your
|> Ph: +61 2 805-2909  Fax: -2929   |  boss fires you." L. Wall & R. Schwartz

-- 
==================
Chris Volpe
G.E. Corporate R&D
volpecr@crd.ge.com
Newsgroups: comp.lang.c
From: berg@physik.tu-muenchen.de (Stephen R. van den Berg)
Subject: Re: Memory alignment of struct elements
Originator: berg@tabaqui
Organization: Rechnerbetrieb Informatik  /  RWTH Aachen
Date: Thu, 13 Aug 92 13:10:05 GMT

>I am writing the software for a big database and the space is very
>important. If I try to use a 

>struct { char ch ; float f }

>the compiler (both in SunOS 4.0.1 and Interactive SYSVR3) allocates
>8 bytes for it, starting the "f" element at fifth byte of the structure.
>This makes both reading and writing such records from/to a binary database 
>file (consisting of 5-byte-long records) very inconvinient, requiring
>a declaration of character array of 5 bytes and using "memcpy()". Is there 
>a way to force the compiler to align the struct elements following their 
>true length?

What you should do in such a case, is to arrange all the elements in the
struct in reverse size order.  Of course, this order might be a bit compiler
dependent, but you can make good guesses about it, and in your case, it
will probably be portable to every machine you will ever need it on.

So, declare the struct as:

	struct mystruct {float f;char ch;};

And, for reading and writing this struct, use the following length:

#define sizeof_mystruct	(offsetof(struct mystruct,ch)+sizeof(char))

Which will, most probably, be five on both architectures; do note however that
the actual size of the struct will still be eight.

This, of course, is only useable if you have the ability to reverse the order
(i.e. the database file format is still changeable), and you don't try to
read complete arrays from the database at once.

In all other cases, using memcpy is inevitable, since alignment (e.g. on
SPARCs) is not for the compiler to determine, it often is hardware dependent.
-- 
Sincerely,                                  berg@pool.informatik.rwth-aachen.de
           Stephen R. van den Berg (AKA BuGless).    berg@physik.tu-muenchen.de

"Good moaning!"
From: jeremyt@mizuno.UK.Sun.COM (Jem Tugwell - Sun EHQ - Cascade)
Newsgroups: comp.lang.c
Subject: Re: Convert float to a string ?
Date: 20 Aug 92 09:52:13 GMT
Reply-To: jeremyt@mizuno.UK.Sun.COM
Organization: Sun Microsystems, Inc.
NNTP-Posting-Host: mizuno.uk.sun.com

> >This is way too much trouble. Use sprintf(). For example:
> >
> >  float a = 12.34567;
> >  char b[9];
> >
> >  sprintf(b, "%8f");
> >
> >
> >Jake
> 
> uh, make that sprintf(b, "%8f\0", a);, of course.
			       ^^
				This in unnecessary

extract from the man page :-

     sprintf() places ``output'', followed by the null  character
				  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     (\0),  in consecutive bytes starting at *s; it is the user's
     ^^^^
     responsibility to ensure that enough storage is available.

%8f doesn't restrict the width of the value of b to 8 bytes total. The %f defaults
to a precision of 6 so your output will be
	12.345670  = 9 bytes

Your sprintf will overwrite the end of b, 9 bytes from the %8f, your \0 and
the one sprintf added = 11

	If "%8f" is the format string - the width part of the format is 8. 
But the width is the MINIMUM fields width. The field will be padded to 8 if the result is smaller. 

Sprintf makes the field at least 8 bytes width + wider if necessary.
	(K.R V2 pg 243 last paragraph)

	"%2.5f" will restrict to 8 bytes (includes the . ) and still show all
the info in f. 	If you f to 123.34567 sprintf will now overflow b 9 bytes from the
"%2.5f" and the null it adds 

	It is your responsiblity to make sure that b is large enough the take any 
value f might have + the null

Jem
Newsgroups: comp.lang.c
From: wkaufman@us.oracle.com (William Kaufman)
Subject: Re: Pointer/address reluctance
Organization: Oracle Corporation, Redwood Shores CA
Date: Sat, 15 Aug 1992 15:04:36 GMT
X-Disclaimer: This message was written by an unauthenticated user
              at Oracle Corporation.  The opinions expressed are those
              of the user and not necessarily those of Oracle.

In article <l8ojbqINN900@exodus.Eng.Sun.COM> linden@positive.Eng.Sun.COM (Peter van der Linden) writes:
] I take the point that some folks like to distinguish 
] between pointers and addresses because of unusual hardware
] that may include capability or offset bits.  
] 
] However, Joe put his finger on the nub of this by pointing
] out (heh!) that we may simply expand our informal concept 

    Well, let's say you've just bought the new Baron Samadi 2000
computer, the first machine to run strictly on voodoo.  Since pointers
are simply references to the original object,

        person *prez = George_Bush;

may be implemented as a voodoo doll of Bush.  And C should support such
a machine.

        resign(prez);
        prez = Dan_Quayle;

            Bus error,...world dumped.

    More seriously, the reason *I* avoid it is because there's always
someone out there who thinks that all memory is byte addressable, and
therefore, all pointers are integers representing a byte index into
memory.  They come up with things like storing a pointer in an int, and
using pointers to different types interchangeably.

    On a weekly basis, I see utter confusion pass over peoples' faces
when I tell them, That's not true!  (It certainly happens here often
enough,...)  It's just so much easier to imagine pointers as sheer
magic, and treat them with the reverence they deserve.

                                           -- Bill K.

Bill Kaufman,          | "Hush my darling / Be still my darling /
Corporate Lackey       |  The lion's on the phone,..."
wkaufman@us.oracle.com |              -- "The Guitar", They Might Be Giants
Newsgroups: comp.lang.c
From: paul@gaitlab1.uwaterloo.ca (paul j guy)
Subject: meaning of '..\dos\crt0.asm ' error in msc 6.0
Summary: What is PWB really trying to say ?
Keywords: startup,MSC6.0,crt0.asm
Organization: University of Waterloo, Waterloo, Ontario, Canada
Distribution: na
Date: Wed, 19 Aug 1992 16:07:59 GMT

	Every once in a while I get a message from PWB (programmers
work bench, MSC6.0) complaining that \dos\crt0.asm does not exist. Then
the linker bitches about one of the library files (or even crt0.obj).
I get an error L2029 '_main' unresolved external. In desperation,
I went through the 'startup' batch file, and generated all the .obj
startup files for the models I use, and it complained about crt0.obj .
Oddly enough, 'main' is declared externalP in crt0.asm .
	I think between me and PWB I am sending myself on a wild
goose chase. In its own cryptic way, the compiler is trying to tell me
something, and I damned if I can figure out what it is.
	When I set up the compiler, I did not make any combined libraries,
instead I have a long list which I link to at the link phase. I have
a suspicion that there is something missing. Usually I get these errors
if I link an additional .obj file (like setargv.obj). Most of the time
I can work around the errors (by directly adding the .obj files to the
appropriate .lib file), but it would be handy to know what's really the
problem.
	I couldn't find this in any FAQ lists, the legitimate MSC6.0 docs,
and no one around here has any idea.
	Thank you for any ideas...

	-Paul

-- 
-----------------------------------------------------------------------------
Paul J Guy			work phone:519-885-1211 ext 6371  
paul@gaitlab1.uwaterloo.ca	home/FAX/message:519-576-3090
pguy@healthy.uwaterloo.ca	..remember...bullshit baffles brains...
Newsgroups: comp.lang.c
From: djs@controls.ccd.harris.com (Dan J. Smith)
Subject: Question about lex
Originator: djs@rs2
Organization: Harris Controls
Date: Thu, 13 Aug 1992 14:58:03 GMT



I'm trying to call the lex output functions generated by two different lex input
files from the same program. But, they both generate output functions called
yylex and have the same global variables so this does not work.

My question is: Is there any way to link two lex output files into
the same program. I've had several ideas but they turned into dead ends pretty 
quickly.


Thanks in advance.
Dan Smith
djs@ccd.harris.com

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Daniel J. Smith                      Phone: (407) 242-5191
Harris Controls and Composition      Email: djs@ccd.harris.com
Melbourne Fl.
Newsgroups: comp.lang.c