HDTenEightyP/NetNews huggingface dataset:
From: a7657@mindlink.bc.ca (Stephen H. Kawamoto)
Subject: how to write C code so that redirection works
Organization: MIND LINK! - British Columbia, Canada
Date: Sun, 10 Jan 1993 03:51:36 GMT

i have a minor problem with C in that when i have a compiled file, FOO
FOO <infile >outfile
wont work. it 'hangs' and a ctrl-c or ctrl-break results in the outfile
having more bytes in it (stuff from the uninitialized memory space i think).

it's the CTOPAS.C source, which turns Pascal into Pascal-like pseudocode (not
true Turbo Pascal in any case).

here's the main where the problem might lie:

>>
>> void main()
>> {
>>    char c, *letter, word[100];
>>    int wordlnth;
>>
>>    letter=word;
>>    wordlnth=0;
>>    while((c=getchar()) != EOF) {
>>       if(isalpha(c)) letter[wordlnth++]=c;
>>       else {
>>          if(wordlnth>0) {            /* word ready to check
>> */
>>             letter[wordlnth]='\0';
>>             wtest(word);             /* pass or replace it
>> */
>>             wordlnth=0;              /* reset index */
>>          }
>>          ctest(c);                   /* process following
>> character */
>>       }
>>    }
>> }   /* Note:  the last word in the file will be missed if it
>> followed by EOF with no intervening nonalphanumeric
>> characters.  This is not a problem for Pascal or C source
>> files.  */



--
address Email to reach me: <a7657@mindlink.bc.ca>||<an3364@anon.penet.fi>
    "It is the very mind itself
     That leads the mind astray;
     Of the mind,
     Do not be mindless."
     (an old Japanese folk song)
From: corteenc@kirk.msoe.edu
Newsgroups: comp.lang.c
Subject: Problems with SIO interrupts.
Date: 9 Jan 93 15:11:59 CDT
Distribution: usa
Organization: Milwaukee School Of Engineering, Milwaukee, WI USA

Hello.

  I am new to the newsgroup, so I hope that this is a relevant question.
I have written a program that reads character data from my modem on COM2.
This code uses polling so, once in a while, i will miss a character. I suppose
that I must use interrupts to read the characters into a buffer whenever
COM2 needs servicing. Is there a way to set the interrupt vector to do
this for me, using the Turbo C setvect function?
I'm really stuck on this one.


Any help would be appreciated.

Thanks,

Chris.

E-mail: corteenc@kirk.msoe.edu
Xref: sparky comp.lang.c:19499 comp.lang.c++:18901
From: dak@tabaqui.informatik.rwth-aachen.de (David Kastrup)
Newsgroups: comp.lang.c,comp.lang.c++
Subject: Re: C/C++ Speed
Date: 10 Jan 93 20:03:59 GMT
Organization: Rechnerbetrieb Informatik - RWTH Aachen
Distribution: usa
NNTP-Posting-Host: tabaqui.informatik.rwth-aachen.de

dliao@aludra.usc.edu (David Liao) writes:

>	Two programmers are writing the same program but with different
>languages which are C and C++.  These two programmers are experts in 
>their own programming language.  Hmm... which program will run faster
>than the other?

>	I've heard that the execution speed of C++ tends to be slower
>than C.  I know that C++ can make the life of programmer easier, but
>I just want to know if the C program will run faster than the C++ program.

>	I also heard the size of C++ program is generally bigger than C.
>I am a C programmer trying to learn C++.  So, don't blame me if I have 
>created any misconception about C++.

For one minor detail: including printf/scanf can include more code than
is actually used. An intelligent C++ linker will only get that parts
of the stream library REALLY needed.

Then comparing C++ to C in speed will usually result in C++ being very
slightly slower, IFF the same job with the same methods is done in both
languages. But that's just it.

When you are using C++, you are much more likely to be able to reuse
efficient shrinkwrapped classes somebody else made for something
different or just as part of a class library.

Furthermore, having the possibility to encapsulate will make you
bolder in choosing your algorithms, in as far that suitably choosing
appropriate class mechanisms will allow you to cleaner partitioning
into subproblems.

Complete projects in C++ tend to be more efficient than C projects,
just as complete projects in C tend to be more efficient than
Assembler projects...
From: mccall@mksol.dseg.ti.com (fred j mccall 575-3539)
Newsgroups: comp.lang.c
Subject: Re: adding strings together
Date: 7 Jan 93 16:42:38 GMT
Organization: Texas Instruments Inc

In <83017@mavenry.UUCP> nider@mavenry.UUCP writes:

> can't you just add strings together with a +, like:
> 
> string3=string1+string2
>  

What do you think you're working in?  BASIC?

-- 
"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.
Newsgroups: comp.lang.c
From: epp4010@ultb.isc.rit.edu (E.P. Pylko)
Subject: Re: Think C 4.0 and Debugger at System 7
Originator: epp4010@ultb
Organization: Rochester Institute of Technology
Date: Tue, 5 Jan 1993 18:15:58 GMT

In article <1i8hojINNjp3@iskut.ucs.ubc.ca> jungjk@unixg.ubc.ca (Jinki Jung) writes:
>
>	Hi,
>
>		I try to use Think C with Debugger function on. 
>	Every time I RUN a project, the screen get frozen in the middle of
>	processing. According to the manual, using Debugging function requires
>	at least 2MB of memory. I have total 4 MB of memory and use System 7.
>	I wander why this is so. 
>
>		If this is not good place to ask, I would appreciate if
>	anyone point me a proper newsgroup.
>
> 	Jung JK (jungjk@unixg.ubc.ca) 
>

The debugger for Think C v4.0 is not compatible with System 7.  Upgrade
to Think C v5.0.  Also, I don't think version 4.0 works well with System
7 either.  Programs to update v4.0 are available at most mac archives.


Eric Pylko
From: gt0201g@prism.gatech.EDU (Cynthia Hsin-I Lin)
Newsgroups: comp.lang.c
Subject: Questions on PRINTERS, PRINTING
Date: 10 Jan 93 14:27:59 GMT
Organization: Georgia Institute of Technology

Hello,
	I wrote a C program in MS_Windows and is now tring to convert to 
DOS.  In MS_WINDOWS, the printer setup and init are going through the
Print Manager.  In my program, two thing can be printed.  A text report,
which includes some text and a table.  A graphical report, which is a 
x-y chart.  Now trying to convert this program to DOS using Borland C,
How do I control the printer?  Do I have to write different code for 
different printers?  Is there a command to draw a line on a printer?
Any information or sample program about printing will be appreciated.

Cindy

-- 
Cynthia H. Lin
Georgia Institute of Technology, Atlanta Georgia, 30332
uucp:	  ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!gt0201g
Internet: gt0201g@prism.gatech.edu
Newsgroups: comp.lang.c,comp.lang.c++
From: steve@taumet.com (Steve Clamage)
Subject: Re: C/C++ Speed
Organization: TauMetric Corporation
Distribution: usa
Date: Tue, 12 Jan 1993 16:41:47 GMT

cshaver@informix.com (Craig Shaver) writes:

>Who implements an intelligent C++ linker???  I was under the impression that 
>you get all the functionality in a class when you link, whether you use it 
>or not.  

Most C++ implementations use a linker which works like the linker for C;
often it is the same linker.  With typical implementations, a function
is included in the executable if it is referenced (called or address
taken), or if it is in the same module as something else which is referenced.

If the C++ programmer puts all the class functions in one module, then
any use of the class gets the code for all functions, but not necessarily
otherwise.  Class member functions may be divided up among different
source modules just like ordinary functions.

That is the situation in C++ for non-class functions, and for class member
functions which are not "virtual".

If a class has "virtual functions", their addresses are usually kept in
a table which becomes part of the executable.  This means that all the
virtual functions are referenced by this table, and thus included in
the program whether or not they are called.  The C++ language does not
require this implementation of virtual functions, but it is the usual case.

The situation is comparable to a C programmer making a table of
functions or a switch statement which might call any of several functions.
The functions get linked into the program whether or not they are called.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com
From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.lang.c
Subject: Re: Problem with string processing.
Date: 11 Jan 93 18:39:38 GMT
Organization: negligable

In article <1993Jan11.060615.2180@eagercon.com> eager@eagercon.com writes:
>In article 1idn10INNpvg@calamari.hi.com, rogers@calamari.hi.com (Andrew Rogers) writes:
>>In article <Ts3TwB1w165w@wozzle.linet.org> alane@wozzle.linet.org (J. Alan Eldridge) writes:
>>>>         char tmp[2] = {0};
>>>>  
>>>>         *tmp = ch;
>>>>         strcat(str, tmp);
>>>
>>>tmp[0] has a 0 in it but tmp[1] is undefined. You are not creating
>>>a nul-terminated string here.
>>
>>tmp[1] most certainly does have a 0 in it; if the initialization list for
>>an array contains fewer elements than the array itself, then the remaining
>>array elements are initialized to 0.  Check the ANSI spec, or the relevant
>>section in K&R.
>
>Well, the relevent section is 3.5.7, which says, in part "If an object that 
>has automatic storage duration is not initialized explicitly, its value is
>indeterminate."  Lacking a 'static' declaration and being within a function
>means that tmp has automatic storage.  Only the first element is initialized
>to zero, tmp[1] is undefined.
>
>For static storage objects, all uninitialize elements get binary zero values.

tmp[0] and tmp[1] are NOT separate 'char's, they are a part of an
array, the initialization of which is governed by it's own set
of rules.

In K&R (the original, sorry) section 4.9, near the end, regarding 
array initialization it says "If there are fewer initializer than 
the specified size, the others will be zero."

I am certain that this rule has been carried up.  I do not have
the ANSI document, however, to check.  The equivilant section for
the C++ ARM, "8.4.1 Aggregates" where it says "If there are fewer 
initializers in the list than there are members of the aggregate, 
then the aggregate is padded with zeros of the appropriate types."  
I would expect that the ANSI C doc is closer to this than the 
original K&R.

		-Richard Hartman
		hartman@uLogic.COM

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Disco isn't dead...			...it's just in witness protection!

Xref: sparky comp.lang.c:19384 rec.humor:37571
From: rkorczyk@sadis05.kelly.af.mil (RICHARD KORCZYK - SCD)
Newsgroups: comp.lang.c,rec.humor
Subject: Re: Program to convert .EXE to a "C" source file?  I really need one!!
Date: 7 Jan 93 20:55:45 GMT
Followup-To: comp.lang.c
Organization: NA

In article <C0FEz5.99I@brunel.ac.uk> Steve.Lake@brunel.ac.uk (Steve M Lake) writes:
>OK, so I know that de-compilers exist, but de-compiling to C source ??????
>I thought that they could only de-compile to Assembler.
>
>Anyway, who would WANT a copy of WordPerfect 2.whatever in C source, I have
>enough trouble understanding my own C code, but code written by a decompiler
>would be even worse. Still, having said all of that, If it does exist
>(The C Decompiler, not WordPerfect 2) can someone tell me where
>
>And if all of this is one big joke, well, I guess i've been fished in.

WHAT IS THIS POST DOING IN rec.humor?

Read before posting.
Newsgroups: comp.lang.c
From: mikee@seas.gwu.edu (Mike Me)
Subject: Re: Borland C text-mode question
Organization: George Washington University
Date: Sat, 9 Jan 1993 06:53:52 GMT

Hi folks, whats up?

I have a quick question for ya.

If I want to draw a little border in text mode under borland C using
the gotoxy() function and putch().

If I get to the last line of the screen, and I place the cornerstone
piece It automatically puts in a CR which shifts the whole frame up
1 line.

Please help,
	Thanx,
		MikeE
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.lang.c
Subject: Re: Conversion of BASIC code to "C"
Date: 12 Jan 93 00:30:07 GMT
Reply-To: dave@cs.arizona.edu (Dave Schaumann)
Organization: University of Arizona

In article <1993Jan10.131651.1@csbina.csubak.edu>, camp5@csbina writes:
>In article <1993Jan8.183821.20711@adobe.com>, (Scott Sivi) writes:
>> Does there exist a method or application by which BASIC files can be
>> converted 
>> to "C".
>You probably couldn't even do it by hand unless the BASIC program was 
>completely flowed and never used a GOTO! The way BASIC programmers spaghetti-
>code programs, I doubt it's possible. (I'm assuming you won't use goto in C.
>I wouldn't.)

Eh, you could do it.  But given the sort of code you could generate, you'd
probably be better off either hand-porting the code to C, or writing/buying
a BASIC compiler.

For instance, consider the simple BASIC program

	100 FOR I=1 TO 10
        110 GOSUB 200
        120 NEXT I
        130 END
        200 PRINT "I=";I;"I^2=";I*I
        210 RETURN

Might "compile" to something like

int line[] = { 100, 110, 120, 130, 200, 210, -1 } ;

main() {

  int pc = 0 ;
  int uv_i ;
  for( pc = 0 ; 1 ; pc++ )
    switch( line[pc] ) {
      case 100: uv_i = 1 ; break ;
      case 110: GOSUB(200) ; break ;
      case 120: uv_i++ ; pc = 1 ; break ;
      case 130: exit(0) ;
      case 200: printf( "I= %d I^2 = %d\n", uv_i, uv_i*uv_i ) ; break ;
      case 210: RETURN ;
      default : printf( "SYSTEM ERROR\n" ) ; exit(1) ;
      }

  }

GOSUB() would be a function that would push the current value of "pc" onto
a stack, look up the appropriate label in the line[] array, and make that
index the new value of "pc".  RETURN would then be a macro that pops the
top of the "pc" stack into pc.

Of course, if maintainability is a concern, you would probably make some
changes to make the program look more like BASIC (perhaps defining
macros for each BASIC statement...).  One obvious problem with this is
that you're going to get one huge case statement inside one huge routine.
Such a method is very likely to run into compiler limitations very quickly.

Perhaps a more "modern" version of BASIC (perhaps with some helpful
constraints) could be translated in a more one-to-one manner.  Ultimately,
I think you'll find that one of my original suggestions is the most practical,
though...

-- 
[An intertialess drive] is not probable at all, at least in any extrapolation
of present-day science.  But as far as I can determine, it cannot be proved
absolutely impossible, and that is enough for me.        -E. E. "Doc" Smith
From: johnl@informix.com (Jonathan Leffler)
Newsgroups: comp.lang.c
Subject: Re: struct vs. typedef
Date: 11 Jan 93 17:09:37 GMT
Organization: Informix Software, Inc.

In article <JAR.93Jan10152829@solva.ifi.uio.no> jar@solva.ifi.uio.no (Jo Are Rosland) writes:
>In article <uRL4wB7w165w@cybrspc.uucp> Roy M. Silvernail writes:
>
>   typedef struct n {
>       int x,y;
>       struct n *last,*next, *up, *down;
>       void (*show)(struct n *);
>       int width;
>       void **value;
>   } ITEM;
>
>   Now, this works, but it sure seems clumsy.  Is this really the only way
>   to do this type of construct?  If not, is it the optimal solution, or is
>   there some extremely clever trick I'm missing?
>
>Given C, that's the best you can get.  You'll just have to get used to
>it, just like the rest of us :-).

Not so:

typedef struct n ITEM;
struct n {
       int x,y;
       ITEM *last,*next, *up, *down;
       void (*show)(ITEM *);
       int width;
       void **value;
};

I prefer the style:

typedef struct Tag Tag;
struct Tag
{
	...
};

where the structure tag and the typdef name are the same -- it gets closer to
C++ that way.
From: david.brooks@cutting.hou.tx.us (David Brooks) 
Newsgroups: comp.lang.c
Subject: Amiga Programmers?
Date: 3 Jan 93 14:16:00 GMT
Distribution: world
Organization: The Cutting Edge - Houston, TX - 713-466-1525
Reply-To: david.brooks@cutting.hou.tx.us (David Brooks) 

   If there are any Amiga C programmers in here, I'm looking for help wit
a requester problem. I'll not post it here since it is a system specific
question, but I don't have access to any of the Amiga specific groups.
Please leave e-mail if you think you can help...

   Thanx!

David

david.brooks@cutting.hou.tx.us

 * Q-Blue v0.7 [NR] *                                             
----
+---------------------------------------------------------------------+
| The Cutting Edge BBS (cutting.hou.tx.us)    A PCBoard 14.5a system  |
| Houston, Texas, USA    +1 713 466 1525          running uuPCB       |
+---------------------------------------------------------------------+
From: mikey@ontek.com (euphausia superba)
Newsgroups: comp.lang.c
Subject: Re: How can you evaluate an arbitrary function?
Date: 8 Jan 93 21:43:47 GMT
Organization: Ontek Corporation -- Laguna Hills, California

In comp.lang.c, slahiri@jade.tufts.edu (Sandip Lahiri) writes:
| Suppose you have to write a program which would accept any arbitrary 
| function f(x) and calculate its values for x = ... . The program has 
| to be written in C. How would you go about it ? Note, common lisp 
| does have the eval primitive and this task is considerably easier
| if the program is written in lisp. Should you write a parser first to
| check the input ? Remember we can have a function nested to any 
| arbitrary depth e.g. f(x) = tan(tanx + sin(cos(sinx + x^2)) + 5).

This is a bit cheeky, but if you'd be allowed to use LISP's eval, I see 
no reason why the following shouldn't be fair play.

---
#include <stdio.h>

#define PART1  "#include <stdio.h>\n#include <math.h>\n"
#define PART2  "main(argc, argv) int argc; char * argv;\n"
#define PART3  "{ double x, f();\n  scanf(\"%lg\", &x);\n"
#define PART4  "  while(!feof(stdin)) {\n"
#define PART5  "    printf(\"f(%lg) = %lg\\n\",x,f(x));\n"
#define PART6  "    scanf(\"%lg\",&x);\n  }\n}\n"
#define PART7  "double f(x) double x; \n{ return ("
#define PARTZ  "); }"

#define TEMP_SRC  "tempXXtemp.c"
#define TEMP_RUN  "./tempXXtemp"
#define CC_PATH   "cc"

#define FROM_X  0.00
#define TO_X    2.05
#define INC_X   0.10

main()
{
  char formula[1000];
  double i;
  int status;
  FILE * fs;

  printf("please type in a formula in terms of x:\n");
  gets(formula);

  fs = fopen(TEMP_SRC, "w");
  fwrite(PART1, 1, strlen(PART1), fs);
  fwrite(PART2, 1, strlen(PART2), fs);
  fwrite(PART3, 1, strlen(PART3), fs);
  fwrite(PART4, 1, strlen(PART4), fs);
  fwrite(PART5, 1, strlen(PART5), fs);
  fwrite(PART6, 1, strlen(PART6), fs);
  fwrite(PART7, 1, strlen(PART7), fs);
  fwrite(formula, 1, strlen(formula), fs);
  fwrite(PARTZ, 1, strlen(PARTZ), fs);
  fclose(fs);

  printf("compiling...\n");
  sprintf(formula, "%s %s -o %s -lm", CC_PATH, TEMP_SRC, TEMP_RUN);
  status = system(formula);
  if (status != 0) exit(1);

  fs = popen(TEMP_RUN, "w");
  printf("running...\n");
  for (i = FROM_X; i < TO_X; i += INC_X)
  {
    fprintf(fs, "%lg\n", i);
  }
  pclose(fs);

  unlink(TEMP_SRC);
  unlink(TEMP_RUN);

  return 0;
}
Newsgroups: comp.lang.c
From: hanafey@eplrx7.es.dupont.com (Mike Hanafey)
Subject: "const" Parameter compatibility 
Keywords: prototypes const
Organization: DuPont Central Research & Development
Date: Thu, 7 Jan 1993 15:44:48 GMT

Are the compiler messages below a bug, or is this correct ANSI C? Also,
the lack of a warning on line 20 appears inconsistent with the warnings
for lines 15 and 16.

"test.c", line 15: warning: argument is incompatible with prototype: arg #1
"test.c", line 16: warning: argument is incompatible with prototype: arg #1

     1  int funca(const int **a) {
     2      return **a;
     3  }
     4  
     5  int funcb(const int *a) {
     6      return *a;
     7  }
     8  
     9  main(void) {
    10      int *b;
    11      int **bp;
    12      const int *c;
    13      const int **cp;
    14  
    15      (void) funca(&b);
    16      (void) funca(bp);
    17      (void) funca(&c);
    18      (void) funca(cp);
    19  
    20      (void) funcb(b);
    21      (void) funcb(c);
    22  
    23      return 0;
    24  }


Mike Hanafey
hanafey@suncity.es.dupont.com
-- 
Newsgroups: comp.lang.c
From: derijkp@reks.uia.ac.be (Peter De Rijk)
Subject: Problem with Turbo-C: calculating with pointers
Organization: U.I.A.
X-Newsreader: Tin 1.1 PL5
Date: Thu, 7 Jan 1993 11:22:19 GMT

I am porting a program (working on different platforms such as VAX and DEC) to
the PC. I am using Turbo C++ v.3.0. I compile using the huge memory model.
I seem to have tracked down the problem (well, one of the problems.) I don't
know what to do about it though. Here's a little program to illustrate the
problem:

#include <alloc.h>

main()
{
char *pointer,*begin,*end;
long size;

size=71800;
pointer=(char *)farmalloc(size*sizeof(char));
begin=pointer;
end=pointer+size;
printf("%p %p %ld",begin, end, end - begin);
}

I would expect end - begin to return 71800. However it seems to return 6264.
This is exactly 64K less.
If this happens for all pointer calculations, I'm in big trouble.
Any ideas to solve this.

All help is greatly appreciated.

Peter
From: jaenicke@emserver.ee.tu-berlin.de (Lutz Jaenicke)
Newsgroups: comp.lang.c
Subject: Re: ** in C
Date: 5 Jan 1993 09:06:26 GMT
Organization: TU-Berlin, Institut fuer Elektrische Maschinen
NNTP-Posting-Host: emws1.ee.tu-berlin.de

In article <C0D3xs.1y2@NeoSoft.com> martink@NeoSoft.com (Martin Koistinen) writes:
>I have a function that needs a 2D array. So I declared it as follows:
>double *My_Function(double A[3][3])
>{
>	static double R[3];
>      .
>   return((double *)&R);
>}
>I have a header file that declares it as:
>double *My_Function(double **)
>My code refers to it as:
>double M[3][3];
>double *p;
>p = My_Function(M);
> 
>I have two questions:
>1) Is there any reason why I shouldn't return a pointer to a static from a
>function? I realize that I may get bad results if I try to reference the
>pointeaafter I do another call to the function or try to use it twice in
>the same statement but is there anything else?
If you are aware of the mentioned properties, you may use it. Many system
calls (e.g. getpwuid as mentioned in another thread today) use this
technique, too.

BUT: You should have a look at your return statement, you do return
"pointer to an array of double", which is pointer to the pointer to the
first element. Your compiler gives you no warning? Then have a look at your
wrong casting. You want to return "pointer to the first element", which
is
	return R;	/* No casting needed */


>2) My compiler gives me a warning that I am passing the function something
>other then what it wants. Why?
> 
>My code seems to work great but I feel better when my compiler doesn't
		  ^^^^^^^^^^ I doubt this
>give me warnings. It was my understanding that n Dimensional arrays break
>down into pointers (n references).
NO!!! One dimensional arrays are equivalent to pointers.
The pointer<->array equivalence DOESN'T hold for multidimensional arrays.
Please have a look into K&R (II) and the excellent FAQ, where this
problem is disussed.

	Lutz
-- 
Lutz Jaenicke 				jaenicke@emserver.ee.tu-berlin.de 
Institut fuer Elektrische Maschinen	jaenicke@emapollo.ee.tu-berlin.de
Technische Universitaet Berlin		Tel. (004930)314-24552
Einsteinufer 11, D-1000 Berlin 10 	Fax. (004930)314-21133