HDTenEightyP/NetNews huggingface dataset:
From: rdorich@jade.tufts.edu (Rob)
Newsgroups: comp.lang.c
Subject: Re: Peek/Poke in C
Date: 22 Dec 92 04:53:55 GMT
	<1992Dec20.011645.17632@philmtl.philips.ca>
Organization: Tufts University - Medford, MA

Will this still work even if you try to look at another page which is
not ours?  I thought this would give us a nice segmentation fault...

Just wondering...

Rob
--
-------------------------------------------------------------------------------
Roberto Dorich		 |           /~~  \ /  ~~/~~ /~~/  /~~  /|  /    /~~
			 |    SKI   /--    X    /   /__/  /--  / |/ |   /--
Electrical Engineering	 |         /__    / \  /   /\    /__  /     |  /__
rdorich@jade.tufts.edu	 |  Tufts University, College of Engineering.
-------------------------------------------------------------------------------
Newsgroups: comp.lang.c
From: mccall@mksol.dseg.ti.com (fred j mccall 575-3539)
Subject: Re: C code Layout
Organization: Texas Instruments Inc
Distribution: usa
Date: Mon, 28 Dec 1992 16:25:12 GMT

In <BzqIHE.7p3@rahul.net> kpapai@rahul.net (Ken Papai) writes:

>nmp@mfltd.co.uk (Nic Percival (x5336)) writes:
>>In article <1992Dec23.153137.13423@fcom.cc.utah.edu>, 
>swillden@news.ccutah.edu (Shawn Willden) writes:
>>> hartman@ulogic.UUCP (Richard M. Hartman) writes:
>>> 
>>> [ Styles A and B deleted (you already know what they are) ]
>>> 
>>> : ... am I in the minority here by preferring style C: and VI editor!!!!

>>> coding styles are discussed massive *FLAMAGE* and LOTS OF SHOUTING IS
>>> REQUIRED TO DO THE SUBJECT JUSTICE???????
>>> 
>>> In keeping with internet custom I would suggest to Mr. Hartman that he
>>> GET A LIFE AND A REAL EDITOR LIKE EMACS AND STOP SCREWING AROUND WITH
>>> VI FOR HELLS SAKE MAN DONT YOU KNOW THIS IS THE 90S???!?!?!?  YOUR
>>> PROBABLY ONE OF THOSE PINKOCOMMIE WHITESPACELOVING FREAKS TO!!!!
>>> 
>>> : -Richard Hartman
>>> : hartman@uLogic.COM
>>> 
>>> --
>>> Shawn Willden
>>> swillden@icarus.weber.edu
>>> 
>>> P.S. I prefer style C myself

>>Get a life? Get a real editor like EMACS? At the risk of getting off the
>>subject, EMACS is poo, full of disgusting cryptic control sequences
>>(what was it CNTRL-X CNTRL-S to save?) and vi is quite wonderful and sexy
>>and fun and great and etc etc.

>>P.S I've got some macros for vi that solve mazes. Try that in poo. Sorry,
>>EMACS.

>I THINK EMACS editors AND VI SUCK BIG TIME!  HAVE USED 'EM BOTH, NONE
>COME CLOSE TO EDITING ON THE PC WITH BRIEF.  ha ha ha hah hah ha!!!!!
>BRIEF BLOWS AWAY *all* COMPETITORS.  the *best*

>and I like style C format too:

>    if (editor == BRIEF)
>         {
>         printf( "You are a lucky software engineer.\n" );
>         printf( "You will be rewarded handsomely because you are so 
>                  productive!")
>         }
>    else
>         printf( "You are an unlucky VI or EMACS user. Sorry..." ); 

And you obviously grew up on Pascal and PC's.  Now, what do you do
when you have to work (simultaneously) on: VAX/VMS, SGI/MIPS UNIX,
MCS-68k OS-9, SunOS, and MS-DOS?  Gee, sorry, but you're too
unproductive trying to run Brief on VMS . . . 

One editor to find them all, and in the darkness bind them . . . 

-- 
"Insisting on perfect safety is for people who don't have the balls to live
 in the real world."   -- Mary Shafer, NASA Ames Dryden
------------------------------------------------------------------------------
Fred.McCall@dseg.ti.com - I don't speak for others and they don't speak for me.
From: kdq@quest.UUCP (Kevin D. Quitt)
Newsgroups: comp.lang.c
Subject: Re: Question to test general C knowledge
Date: Tue, 22 Dec 92 17:54:07 PST
Reply-To: srhqla!quest!kdq
Organization: Job quest  (805) 251-8210,  So Cal: (800) 400-8210

mouse@thunder.mcrcim.mcgill.edu (der Mouse) writes:
> sizeof(4["this is a test"])
> must produce 1, or your compiler's broken.

    Either that, or you've got 16-bit chars.


 _
Kevin D. Quitt      96.37% of all statistics are made up.     srhqla!quest!kdq
Newsgroups: comp.lang.c,comp.lang.pascal
From: jhesse@netcom.com (John Hesse)
Subject: Re: Hash Coding Revisited -- need prime number generator
Organization: Netcom - Online Communication Services (408 241-9760 guest)
Date: Fri, 1 Jan 1993 04:28:52 GMT

I'm implementing a hashing algorithm and need a prime-number algorithm.

(At this time the size isn't known, so that's why I need the algorithm.)

C code, or even BASIC, would be extremely helpful. BTW, I need a 6-digit
prime, if that makes a difference. Thanks a million (not a prime :).

Also, I could not find an "algorithms" topic, so that is why I put it
here. Hope no one is upset.

Happy New Year!!!! :-)
-- 
----------------------------+---------------+-------------------------
J Hesse	                    |      END      |    California       
jhesse@netcom.com           |    50 MPH     |     traffic
Moss Beach, Calif           |  SPEED LIMIT  |       sign
----------------------------+---------------+-------------------------
From: surendra@plsparc.UUCP (Surendra Goel)
Newsgroups: comp.lang.c
Subject: Re: Compiling ANSI C on Sun4's
Date: 31 Dec 92 15:25:24 GMT
Distribution: usa
Organization: Personal Library Software, Inc.

Sun also has the ANSI-C compiler which you have to buy separately. It costs
quite a bit (~$2000).

-- 
Surendra Goel (surendra@pls.com)
Personal Library Software, Inc.  2400 Research Blvd. Suite 350, Rockville, MD 20850   Phone: (301)926-1402 
Newsgroups: comp.lang.c
From: dietz@parody.Data-IO.COM (Kent Dietz)
Subject: Re: Problem with string processing.
Organization: Data I/O Corporation
Date: Sun, 3 Jan 1993 19:41:54 GMT

In article <1993Jan2.233446.20833@iitmax.iit.edu>, matujos@elof.iit.edu (Joe Matusiewicz) writes:
|> 
|>    I am having a little problem with string processing.  I have been
|> programming in C for 6 months, and I just can't figure out the following
|> problem:
|> 
|>    I need a function to append a character to the end of a string.

Try using sprintf():

	sprintf(str, "%s%c", str, ch);

This assumes that str is large enough to hold the new character!

Probably what is wrong with the following code (which you should not
use in my humble opinion) is that calloc syntax is different than 
your usage:

	char *calloc(num_of_elem, elem_size)
	
I suspect that got things confused.

|> I can't find an ANSI function to do so, so I tried to write my own.
|> Here's what I have:
|> 
|> 
|>          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);
|>          }
|> 
|>                                    Joe.


Good Luck,

Kent Dietz
Data I/O Corporation
From: jfw@ksr.com (John F. Woods)
Newsgroups: comp.lang.c
Subject: Re: Question to test general C knowledge
Date: 22 Dec 92 15:05:02 EST

mouse@thunder.mcrcim.mcgill.edu (der Mouse) writes:
>In article <1992Dec16.192652.65097@ns1.cc.lehigh.edu>, dsbb@ns1.cc.lehigh.edu (D. SPENCER BEECHER) writes:
>> D. SPENCER BEECHER) writes:
>>>> varname%3
>>>> varname&0x02
>>> Well, [...]
>> x&0x02 may be represented with modulo as:
>>   x%=4,x>1?x:0;
>> though this changes the value of x, where x&0x02 makes no assignment.
>It also doesn't work.  For example, if x holds 7, x&2 is 2 whereas your
>expression produces 3.  (And, as you note, changes x.)
>I'm also not sure whether , or ?: has higher precedence.  For that to
>work correctly, it has to be interpreted as (x%=4),((x>1)?x:0), but I'm
>not sure it wouldn't be (((x%=4),x)>1)?x:0 instead, which I *think*
>produces undefined behavior.

If C operators had precedence, ?: would have higher precedence, and comma
would have the lowest precedence of all.  Since they don't :-), one simply
needs to note that an "expression" may be "expression , assignment-expression",
and an "assignment-expression" may be a "conditional-expression", which
of course may be "logical-OR-expression ? expression : conditional-expression",
which amounts to the same thing :-).

(((x %=4),x)>1)?x:0  should be well-defined, however:  there is a sequence
point at the comma and at the question mark ("The first operand is evaluated;
there is a sequence point after its evaluation." [1]), and the order of those
sequence points is even well-defined.[2]  So, the modification of x is safely
interred before its value is queried again, and would have been even if the
expression were written

	(x %= 4) > 1 ? x : 0;

[1] Well, it doesn't quite explicitly say that sequence point *preceeds* the
evaluation of the second or third expression, but surely that is the intent
(otherwise the sequence point could have been specified as being for the whole
conditional expression).

[2] Yes, folks, I'm arguing that something *is* defined by the standard.  Now
ain't THAT a shock :-) ?
From: hollasch@kpc.com (Steve Hollasch)
Newsgroups: comp.lang.c
Subject: Re: Accessing a dynamical 3-D field
Summary: Multi-dimensional array element access
Date: 29 Dec 92 19:07:22 GMT
Organization: Kubota Pacific Computer, Inc.

backscha@Informatik.TU-Muenchen.DE (Martin Backschat) writes:
| 
| In my program I use 3-D fields of doubles with variable bounds.
| This field is implemented as an array of doubles which is allocated
| dynamically with malloc.
| To access for example the [i][j][k] component in the field f of dimension
| U,V,W I have to write   f[i*V*W + j*W + k].
| 
| Is it somehow possible to declare and allocate a 3-D field u (of doubles) with
| variable bounds, allocated by malloc, in such a way that it can be accessed
| with u[i,j,k] (with type casting)?

    Quite possibly, but to what advantage?  When the compiler performs a
mutli-dimensional array access, it does this exact computation to yield the
address of the element in question.  There are _some_ CPU's that have
instructions to handle (non-general) 2D arrays, but I don't think there are
many (if any) CPU's that have a single instruction to do a 3D array access.

    So, if you WERE able to typecast this to a multi-dimensional array (I
tried to find a way but gave up), the compiler would still generate this
code.  What I would do is to just write a macro, e.g.:

        #define FIELD(array,i,j,k) \
            array [((((i) * V) + (j)) * W) + (k)]

    So then you could just do "FIELD(f,i,j,k)" to refer to a given element.
Note the way that I computed the index takes one less multiply than the
formula you listed.

______________________________________________________________________________
Steve Hollasch                                   Kubota Pacific Computer, Inc.
hollasch@kpc.com                                 Santa Clara, California
Newsgroups: comp.lang.c,comp.lang.c++,comp.misc
From: nagle@netcom.com (John Nagle)
Subject: Re: What is Object Oriented Programming? Is C doomed?
Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
Date: Wed, 30 Dec 1992 17:36:27 GMT

swillden@news.ccutah.edu (Shawn Willden) writes:
>	Is this scheme similar to the one you had in mind?  If yours
>is better, please share it (or provide references, I suppose I ought
>to check Knuth to see if he has anything like this).
>In any case, I like the idea well enough that I think I'm going to
>start using it.

       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.

					John Nagle
Newsgroups: comp.lang.c
From: pal@regent.e-technik.tu-muenchen.dbp.de (Peter Loibl)
Subject: Re: allocating 2-d array
Organization: Technical University of Munich, Germany
Date: Tue, 22 Dec 1992 21:43:25 GMT

jsd@nynexst.com (Joseph Delotto) writes:

[stuff deleted]

>which seems to work ok but looks awfully sloppy.  Is there any
>way to get the whole thing done in one shot?

No! Not that I would know. BTW: change that unsigned into size_t and
you are more secure.

Peter Loibl
pal@regent.e-technik.tu-muenchen.de
Organization: City University of New York/ University Computer Center
Date: Tuesday, 22 Dec 1992 03:05:27 EST
From: <I35BC@CUNYVM.BITNET>
Newsgroups: comp.lang.c
Subject: Re: VMS c, how to read stream files

send
Borland C++ v3.1 rules dude!!
No but reallly this is an amazing piece of software Borland put out.  It a;lso
retails for around $600 bucks.  It does everything
Newsgroups: comp.lang.c
From: isc@panix.com (David Koosis)
Subject: Re: Yacc/ BNF Form / HELP!
Date: Wed, 30 Dec 1992 19:57:25 GMT
Organization: PANIX Public Access Unix, NYC

In <92364.230231JXU3@psuvm.psu.edu> <JXU3@psuvm.psu.edu> writes:

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

Oh yeah, that reminds me: John Levine & various other
compiler groupies can be found at comp.compilers.

The FAQ posting in comp.compilers is a valuable resource for 
any interested in compilers.  

best,
dkoosis

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ISC Consultants // Technical Training & Consulting Since 1973 // 212.477.8800
Newsgroups: comp.lang.c,comp.sys.ibm.pc.programmer,alt.msdos.programmer,comp.sys.ibm.pc.misc
From: stuart@coral.cs.jcu.edu.au (Stuart Kemp)
Subject: BEWARE! Borland's BCC produces bad code (with example!)
Summary: '-Z' on BCC produces bad code
Keywords: BCC, PC, MSDOS
Organization: James Cook University
Date:  3 Jan 93 01:08:53 GMT


The appended program was gutted from something I am working on ...
If you compile it with "bcc -ml -Z file.c" it will produce bad code;
compile with "bcc -ml file.c" and all is okay. (The output generated should
always list the same segment, with different offsets.) This happens on both
BCC v3.0 and v3.1. Unfortunately, you will never know when this is going
to bite you ... would suggest that you be beware of compiling with (just)
'-O2' (or '-Ox') since this implies '-Z' as well; better to use '-Ox -Z-'.

The "bad" portion of code generated with the '-Z' is in the printf()
statement in the 'for' loop ... the assembly code (generated with '-S') is:

   ;	
   ;	    fprintf(log, "%2d  %p\n", i, T->Hdrs[i]);
   ;	
	mov	es,word ptr es:[bx+6]	; BUG!!!!!
	push	word ptr es:[si+2]
	push	word ptr es:[si]

The marked statement should be omitted completely. Doing so and compiling
the resultant assembly code yields a working program.

Anyone got any other (small!) examples of where compilers produce wrong
code?

-SRK

-------------- Snip Snip -------------
#include <stdio.h>
#include <stdlib.h>

typedef
struct _GTbl
  { void *Data;
    void **Hdrs;
    unsigned short StructSize;
  } GTbl;

FILE *log;

/* Allocates a buffer area, then set some pointers into this area */
/* NULL checks removed while examining assembly code! */
void
Bug(GTbl *T)
{
  short i;

  T->Hdrs = (void**) malloc(10 * sizeof(void*));
  T->Data = (void*) malloc(10 * T->StructSize);

  fprintf(log, "Hdrs: %p\n", T->Hdrs);
  fprintf(log, "Data: %p\n", T->Data);
  for (i = 0; i < 10; i++)
  { T->Hdrs[i] = (void*) ((char*)T->Data + i * T->StructSize);
    fprintf(log, "%2d  %p\n", i, T->Hdrs[i]);	/* BUG IN ASSEMBLY HERE */
  }
}

main()
{
  GTbl T;

  log = fopen("LOG2", "w");
  T.StructSize = 16;
  Bug(&T);
  fclose(log);
  return(0);
}
--
Dept of Computer Science        Internet: stuart@coral.cs.jcu.edu.au
James Cook University
Townsville                      Tel: +61 77 814992
Qld 4811 Australia              FAX: +61 77 814092
Newsgroups: comp.lang.c
From: awright@gssec.bt.co.uk (Alan Wright)
Newsgroups: comp.lang.c
Subject: Re: Need HELP with strptime....any answers/clues?????
Date: 22 Dec 92 18:53:09 GMT
Organization: BT, Software Engineering Centre, Glasgow, UK

In article <1992Dec21.172542.28171@linus.mitre.org>,i
jrv@mbunix.mitre.org (Van Zandt) writes:
|> 
|> >>I have been working with some of the time functions (on a Sun
|> >>SPARCstation IPX).  After I make a call to strptime (to fill 
|> >>in the tm structure) I display the structure (with dbxtool) and
|> >>find that the structure is filled in incorrectly.  What am I 
|> >>doing wrong?
|> ...
|> >>	struct	tm	*my_tm;
|> >> 
|> >>	(void)strptime(timeString,"%Y,%j/%H%M%S",my_tm);
|> 
|> my_tm needs to be initialized to point to a struct tm before
|> asking strptime to fill it in.
|> 
|>                    - Jim Van Zandt <jrv@mitre.org>

I had problems with strptime on the Sun a few months ago and
came to the conclusion that it was broken. Are you saying that
the following should work?

#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>

main()
{
   static char *s = "19920901111500";
   struct tm *tm;
   time_t tloc;

   time(&tloc);
   tm = localtime(&tloc);
   strptime(s, "%Y%m%d%H%M%S", tm);
   tloc = timelocal(tm);

   printf("Converted %s to %s, tloc = %ld\n",
      s, ctime(&tloc), tloc);
}

I have also tried:

int main()
{
   static char *s = "19920901111500";
   struct tm tm;
   time_t tloc;

   strptime(s, "%Y%m%d%H%M%S", &tm);
   tloc = timelocal(&tm);
   ...

No matter how I twist things it always fails.

-- Alan.
--------------------------------------------
awright@gssec.bt.co.uk (Alan Wright)
BT, Software Engineering Centre, Glasgow, UK
--------------------------------------------
Newsgroups: comp.lang.c
From: rince@dcs.warwick.ac.uk (James Bonfield)
Subject: Re: sccs eats good code -
Organization: Department of Computer Science, Warwick University, England
Distribution: comp
Date: Tue, 22 Dec 1992 09:03:29 GMT

In <1992Dec21.4396.29992@dosgate> "peter curran" <peter.curran@canrem.com> writes:

> (As others pointed out, a solution is to get rid of SCCS.  My
> recommendation is to get rid of source code management systems,
> but that would raise a few screams, so I won't mention it.)
> 
> Peter Curran
> Usenet: peter.curran@canrem.com     RIME: CRS (#118)
> ---
>   DeLuxe 1.25 #12339  
> --
> Canada Remote Systems  - Toronto, Ontario
> World's Largest PCBOARD System - 416-629-7000/629-7044

I'd certainly agree with abolishing sccs. I've never really been 'into' source
management systems, but when I have had to use them I've found RCS invariably
better. The first time I was told (had to really to get decent marks in a
course) to use sccs I ended up making the mistake of typing a control
character (accidently) into my source code. Sccs was more than happy to add
this new addition to the history file.

However it showed it's true stupidity when I tried to do an 'sccs edit file.c'
on the file. It appears it follows the following scheme:

1) Check if there is an sccs file for 'file.c'.
	If not error
2) Delete the existing file.c from this directory
3) Parse file.c and attempt to extract the latest revision

Do you notice anything blindingly wrong with this? Sccs has the intelligent
idea of giving control characters special meaning within the history file. And
it doesn't bother to escape any of the ones you happen to have typed in. This,
naturally, means that if you enter a control char into your source then upon
the next 'get' or 'edit' sccs will kindly remove the only existing copy you've
got and *then* complain that it doesn't understand the history file.

For this reason using sccs actually slowed down and hampered my development by
a huge factor. Surely this isn't the scheme of such things? On the contrary
the next time I was asked to make use of such a system I put RCS to the test
(by RCSing a few binaries and seeing how it felt about such monstrosities).
This handled things MUCH better. (Of course, even so I made sure I kept my own
backups and revisions as well... just in case).

-- 
James Bonfield (jkb@mrc-lmba.cam.ac.uk / rince@dcs.warwick.ac.uk)
Medical Research Council Laboratory of Molecular Biology, Hills Road,
Cambridge, CB2 2QH, England. Tel: 0223 402499   Fax: 0223 412282
Newsgroups: comp.lang.c
From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
Subject: Re: Another C palindrome puzzle
Organization: Computer Science, University of Melbourne, Australia
Date: Fri, 25 Dec 1992 21:37:39 GMT

mouse@thunder.mcrcim.mcgill.edu (der Mouse) writes:

>Ron Wichers Schreur <ronny@cs.kun.nl> writes:
>> Manus Hand, manus@evolving.com writes:
>>> Now I suppose I have to come up with the NEXT challenge.
>>> Okaaaayyyy.... how about a palindromic "Hello world" program, with
>>> no comments, #if's, #ifdef's, <<<OR #define's!>>>
>> This looks a real challenge (I don't think there's a solution).
>
>I don't either.  Consider what the first token in such a program might
>be.  I don't think it's possible for its reversal to be the last token.

Did you mean the first source token, or the first preprocessing token?
Don't forget about things like trigraphs, and line continuations with
backslashes. I'm almost certain that there *is* a solution. I've solved the
first/last token difficulty, but the middle is proving tricky.

-- 
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!
Newsgroups: comp.lang.c
From: d90-awe@klara.nada.kth.se (Assar Westerlund)
Subject: Re: allocs, multidim arrays, and FAQ
Organization: Royal Institute of Technology, Stockholm, Sweden
Date: Fri, 1 Jan 1993 03:56:36 GMT

In article <1992Dec31.170307.4524@nsisrv.gsfc.nasa.gov> almeida@ame.gsfc.nasa.gov (aswin m. almeida) writes:
   Recently I attempted to create a small fragment of C
   using the FAQ in the newsgroup.  Here is the fragment
   from:

   [ cites the FAQ ]

   2) The Program I wrote (I am new to C programming, don't laugh <: )
      (Implements the code above).

I've modified your program a little. Here is the modified version:

#include <stdio.h>
#include <stdlib.h> 

int main(void)
{
     int i,j;
     int nrows, ncolumns;
     int **array;
     ncolumns = 10;

     printf ("Enter array index: \n");
     scanf ("%d", &nrows);

     array = (int **) malloc (nrows * sizeof(int *));
     for (i=0; i < nrows; i++)
	  array[i] = (int *) malloc (ncolumns * sizeof(int));

     printf ("Reading array values, and printing\n");
     for (i=0; i<nrows; i++)
	  for (j=0; j<ncolumns; j++)
	  {
	       printf("%d x %d = %d\n",i,j,i*j);
	       array[i][j] = i*j;
	       printf("%d,%d = %d\n",i,j,array[i][j]);
	       
	  }
     return EXIT_SUCCESS;
}

Notes:

1. You should include stdlib.h, malloc is declared there.
2. Better declare main as int main(void) or if you have an "old-style"
compiler int main().
3. Also return a value from main, EXIT_SUCCESS or if don't have an
ANSI-compiler, 0.
4. The main problem you were having is that all declarations must come
immediately after the open brace. I've moved the declaration of array
up.
5. The size in the second malloc should be `ncolumns * sizeof(int)'.
6. You had put the for-loops in the wrong order (or the indexes in the
wrong order).