HDTenEightyP/NetNews huggingface dataset:
Newsgroups: comp.lang.c

In comp.lang.c, booloo@framsparc.ocf.llnl.gov (Mark Boolootian) writes:


> The following piece was written by Jim Minton, an aspiring C programmer.
> I convinced him to let me post it to the net.  Happy reading and flames
> to /nev/dull...



> 		The Correct Way To Write C if-Statements
> 				by
> 			    Jim Minton


> Braces

> Braces belong on children's teeth and around the body of every 
> single if-statement.  There are no exceptions.  Every single if-body 
> is to be surrounded by braces.  The essence of the argument in favor 
> of braces is this: all if-statements should look the same, 
> therefore, if some if-statements have braces (as all with multi-
> statement bodies do) and others (those with single statement bodies) 
> don't, then it is impossible for if-statements to look the same.  
> Either they all have braces or none of them have braces.  Since the 
> language requires that some if-statements have braces, then, to make 
> them all look the same, we have to put braces around every single 
> if-body, even bodies that have only one statement!


Just for the sake of argument (-; doesn't this logic then imply that,
since some if statements have else clauses, all if statements should have
else clauses?

Larry Gajdos
(My being syntactically incorrect should in no way be construed as a reflection
on my employer.)
Newsgroups: comp.lang.c
From: mccall@mksol.dseg.ti.com (fred j mccall 575-3539)
Subject: Re: Is this ANSI C?
Keywords: A bet
Organization: Texas Instruments Inc
Date: Mon, 9 Nov 1992 19:06:07 GMT

In <1dhkrtINNj99@duvel.cs.ubc.ca> hassan@cs.ubc.ca (Moustafa Hassan) writes:

>#include <stdio.h>
>void main(void)
>{
>  printf("hello world\n");
>}

>To settle a dispute, would someone please tell me whether the above
>is ANSI C.  I claim that 'main' (according to the pure ANSI standard)
>must return an integer value, but nonetheless, some non-purists claim
>that the above is ANSI.  Please do not respond via email; I want 
>my opponent (8^) to be able to see all the messages.

Main must return a value to the invocation environment which is of
type int (in other words, you are correct).  Consider that the startup
code 'expects' an integer to come back from your main routine (unless
you go in and edit the startup code).  On many environments, it won't
matter if you change it to 'void' IN THAT ENVIRONMENT.  If you ever
move the code it may matter very much indeed.  And in some
environments, things will die an ugly death at the end of your program
because the startup code popped something off the stack (assuming a
stack) or 'retrieved' a return value in some way and that return
valued doesn't exist.

The CALLED code (in this case, main) can elect to simply ignore
arguments that are there (argc, argv), but you have no control over
the environment you are called from.  Therefore, you should always
explicitly return an integer to the environment from main().

-- 
"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: dfuller@portal.hq.videocart.com (Dave Fuller)
Subject: Re: pointers to functions
Organization: VideOcart Inc.
X-Newsreader: Tin 1.1 PL3
Distribution: na
Date: Sat, 7 Nov 1992 01:19:22 GMT

pendell@deneb.csustan.edu (Brian Pendell) writes:
: Greetings!
: 
: As many of you already know, the declaration
: 
: double (*pfun) ();
: 
: declares pfun to be a pointer to a function which returns double.
: 
: Now, how do I call the function using the pointer? That is, the next
: 
: instruction should be:
: 
: "Call the function pointed to by pfun with parameters A and B"
: 
: function (A,B), in other words.
: 
Brian,
  if A and B were ints, and we were worried about ANSI we would have to 
redeclare it as double (*pfun)(int , int );

then to call it (assuming retval is a double and pfun is the address of
the function) just do this :

retval = (* pfun)(A, B);


Dave Fuller
dfuller@portal.hq.videocart.com
From: kv07@IASTATE.EDU (Warren Vonroeschlaub)
Newsgroups: comp.lang.c
Subject: pixels -> GIF
Date: 9 Nov 92 22:38:01 GMT
Article-I.D.: IASTATE.1992Nov9.163801
Reply-To: kv07@IASTATE.EDU (Warren Vonroeschlaub)
Organization: Ministry of Silly Walks


  Or any other graphic image format that is standard.

  Specifically I am looking for some function that creates a file (or returns
the numbers you should put in a file) of a graphic image when it is fed the
image on a pixel-by-pixel basis.  It doesn't matter if it requires a special
ordering.  (unless the order is completely whacked out, like every other prime
coordinate or something like that)

  Into GIF would be best, but PCX or JPG or whatever is okay.

 |  __L__
-|-  ___  Warren Kurt vonRoeschlaub
 |  | o | kv07@iastate.edu
 |/ `---' Iowa State University
/|   ___  Math Department
 |  |___| 400 Carver Hall
 |  |___| Ames, IA  50011
 J  _____
Newsgroups: comp.lang.c,comp.lang.c++,comp.lang.pascal,comp.lang.misc
From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
Subject: Re: Software design =/= Programming
Organization: MAXTAL P/L C/- University Computing Centre, Sydney
Date: Sun, 8 Nov 1992 03:14:23 GMT

In article <1dcuutINNi8t@agate.berkeley.edu> faustus@ygdrasil.CS.Berkeley.EDU (Wayne A. Christopher) writes:
>In article <1992Nov04.073218.11970@cadlab.sublink.org> martelli@cadlab.sublink.org (Alex Martelli) writes:
>> The point of Goedel's Theorem is, that for *ANY* formal system "powerful
>> enough" ... there will be *true* statements about the formal
>> systems that cannot be proven from that set of axioms!!!
>
>Not exactly -- what it says is that for any set of axioms A there will
>be statements S such that A does not imply S and A does not imply not
>S.  The notion of truth doesn't come into it, since in a formal system
>either something is provable or isn't.
>
>	Wayne

	The notion of truth DOES come into it. The above is only the
first part of the theorem. Statements which cannot be proved or disproved
are called undecidable. Goedel showed that some undecidable statements
can be proved to be undecidable (out side the system) and thus they
must be true (since no counter examples exist). Thus there are true
statements in mathematics which cannot be *formally* proved.

	The proof is truly wonderous to work through.

-- 
;----------------------------------------------------------------------
        JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
	Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
Newsgroups: comp.lang.c
From: rudolph@cyan.Berkeley.EDU (Chuck E. Rudolph)
Subject: Re: Anyone know where I can find awkcc sources?
Reply-To: chuck.rudolph@cigseg.rtsg.mot.com
Organization: Radio Telephone Systems Group, Motorola
Distribution: comp
Date: Fri, 6 Nov 1992 23:51:12 GMT

In article <36738@cbmvax.commodore.com>, dean@cbmvax.commodore.com (Jeff Dean - LSI Test) writes:
>
>I'm looking to find awkcc sources.  Anyone have them or 
>know of a site?  
>

Me too!

-- 
Chuck Rudolph                | Electronic: chuck.rudolph@cigseg.rtsg.mot.com
Motorola Inc, N349           | Voice: (708) 632-2779   Fax: (708) 632-5694
1501 West Shure Drive        |    The meek shall inherit the earth.
Arlington Heights, IL  60004 |    The rest of us are going into space.  -NSS
Xref: sparky comp.lang.c:16132 comp.software-eng:4189 comp.sys.mac.programmer:18119
Organization: University of Illinois at Chicago
Date: Mon, 9 Nov 1992 23:57:22 CST
From: <U17868@uicvm.uic.edu>
Newsgroups: comp.lang.c
Subject: largest structure size on pc (in c)

my  program is listed below. it is very short. All I am trying to do is to
read from a file. But, I think the problem is that the structure size is too bi
g. It compiles successfully.I am using Turbo C 2.0. When I run it I get the mes
sage "Null Pointer Assignment". I tried different ways that is using malloc, wi
thout malloc, defining structure as a tag and then declaring an instance, but n
othing helpded. I have 2M RAM on my pc.Anyone has any suggestion send it to
u17868@uicvm..cc.uic.edu

Thanks,
Sikander
===================my program ============================================
#include <stdio.h>
#include <stdlib.h>
struct {
	int  id;
	char  date[9];
	char day[10];
	int  stime;
	int  length;
	char location[10];
	char with_who[10];
	char phone[11];
	char subj[10];
	char note[10];
        int  flag;
}temp;

main()
{
int i;
FILE *file_pointer;
 file_pointer = fopen("activity.dat","rb+");
 fseek(file_pointer,0,0);

 for(i=0;i<=4;i++)
     {
       scanf("%d",&temp.id);
       gets(temp.date);
       gets(temp.day);
       scanf("%d",&temp.stime);
       scanf("%d",&temp.length);
       gets(temp.location);
       gets(temp.with_who);
       gets(temp.phone);
       gets(temp.subj);
       gets(temp.note);
       scanf("%d",&temp.flag);
       fwrite(&temp,sizeof(temp),1,file_pointer);
       }
 }

Newsgroups: comp.lang.c
From: rfries@sceng.ub.com (Robert Fries)
Subject: Re: Rounding floats to integers
Organization: Ungermann Bass
Date: Tue, 10 Nov 1992 14:16:22 GMT

In article <92314.134711IA8@psuvm.psu.edu> IA8@psuvm.psu.edu (Alan R. Heyd) writes:

>What I do now is add 0.5 to the float before it is converted to
>an integer, for example:

To round to NEAREST integer, you'd have to test if fractional part is less 
than 0.5; if YES, drop fractional part, if NO, add 0.5, then drop fraction.
You'd also get to choose what to do if fractional part is EXACTLY 0.5.

Off the top of my head:

int round(float v)
{
    if ((v - (int)v) < 0.5)	// use '<=' if 0.5 should round down
        return (int)v;		
    return (int)(v+0.5);	 
}	

Robert

//////////////////////////////////////////////////////////////////////////
Robert Fries
Ungermann-Bass Inc.

DISCLAIMER:
    Opinions contained herein are my own, and are not necessarily those
    of Ungermann-Bass.
//////////////////////////////////////////////////////////////////////////
From: cee1@Ra.MsState.Edu (Charles Evans)
Newsgroups: comp.lang.c
Subject: Need help reading floats from file
Date: 7 Nov 92 03:59:03 GMT
Article-I.D.: Ra.cee1.721108743
Organization: Mississippi State University

Ok, in getting data for an experiment to look at, I have
200 .xx floating point number, just a decimal point and 2 decimal
places, put in 20 x 20 in a data file.

How can I read them into an array.. all i could think of was do 
a HUGE fgets/sscanf thing with "%f %f ... %f".. 20 times and put into
20 parts of an array like : value[i++][j] on an on until i=20 then
reset i and increment j..

but i get weird errors from dos and qemm.. something is wrong.
why cant i (i can in basic :)) just keep reading in a floating point number
or read it in as a small string until the first whitespace?

or something. thanks


data file looks like:

.11 .33 .00 .......
.23 .45 .23 .......
 .   .   .
 .   .   .

20 x 20

thanks
chuck

--
+--------------------+-----------------------+------------------------+
|  Charles E. Evans  |  cee1@ra.msstate.edu  |        Fear God        |
|    iDLE CHATTEr    |  cee1@MSSTATE.BITNET  |  Love the brotherhood  |
|    Idle chatteR    |cevans@abe.msstate.edu |  Pray without ceasing  | 
Newsgroups: comp.lang.c
From: dkeisen@leland.Stanford.EDU (Dave Eisen)
Subject: Re: Memory functions  -  memcpy & memmove
Organization: Sequoia Peripherals, Inc.
Date: Mon, 9 Nov 92 06:38:56 GMT

In article <BxFKAw.1A5@portal.hq.videocart.com> dfuller@portal.hq.videocart.com (Dave Fuller) writes:
>I've said it before. I could really not give a shit if the code isn't
>perfect. I don't get paid to do this, and i try to answer a lot of the  
>questions. If someone wants more than a signed int of chars moved, then
>change the code. I only want to see replys when the code is just flat
>out WRONG.

Last I checked, I don't get paid for this either. And I for one
want to see replies if they clear up another post or point out
small problems with another post.

Clearly wrong solutions are not really a problem. The inexperienced
programmer who posted the question will try them out, find that they
don't work, and hopefully look to another source for the answer. 

It's the almost correct solutions that are the most dangerous because
they will not immediately blow up in the beginners face; they will
only cause mysterious problems when the code is ported to a different
environment or if it is compiled with the next release of the compiler
or if it is just pushed to the limits with unusual cases. By the time
this happens, the programmer is forced to go through 50,000 lines of 
code to find the obscure problem he never should have had in the first
place.

Besides, I don't have much of a stake in whether a given programmer
gets a solution to his problem from the net. If he doesn't, I'm sure
he'll muddle through somehow. What I *do* have a stake in is the
general level of correctness in the code written by the C community.
And that means I don't like seeing sort of almost correct code
posted here.

>second, why the hell would it even need to match the ansi code for
>memmove. this isnt even called memmove. it was designed to take the 
>place of it where it didn't exist yet. Therefore, there isnt a damn
>standard to follow. so someone needs to cast (char *) to call this.
>I couldn't care less. don't like it, change it. but it works, so 
>please quit giving me some B.S. style guide lessons.

They aren't giving *you* a "B.S. style guide lesson." They are trying 
to give the entire net a "B.S. style guide lesson", if that's how you
want to see their (and my) posts. We're trying to help people write
more correct code. If you don't want to be helped, feel free to ignore 
any followups to your articles. Including this one.



-- 
Dave Eisen                               Sequoia Peripherals: (415) 967-5644
dkeisen@leland.Stanford.EDU              Home:                (415) 321-5154
       There's something in my library to offend everybody. 
          --- Washington Coalition Against Censorship
Newsgroups: comp.lang.c
From: steve@taumet.com (Steve Clamage)
Subject: Re: Finding length of file?
Organization: TauMetric Corporation
Date: Mon, 9 Nov 1992 19:13:16 GMT

ceblair@ux1.cso.uiuc.edu (Charles Blair) writes:


>  Sorry if this is an FAQ, I couldn't find it in any of the current 
>postings.

>  I have created a file for reading using fopen.  Is there a simple
>quick way to find out how many bytes there are until EOF?  I would
>prefer something that is part of the standard, which I think rules
>out the read command.  I thought I might be able to do this using
>p -> cnt for p a pointer to FILE, but that didn't work.

The only Standard-conforming and portable way to find out how many
bytes are in a file is to open the file (or seek to its beginning),
and read bytes until EOF, keeping track of how many you read.

Because of the diversity of file systems, you are not guaranteed in
either text or binary mode that what you wrote to a file is precisely
what is in the file.  That is, for example, lines in a text file might
have more or fewer trailing blanks than you wrote, and a binary file
might have more or fewer trailing nulls than you wrote.  There are
other issues as well.

C implementations often provide functions which tell you many things
about files, including size.  For example, stat() and fstat() are
common functions, but not part of the C Standard.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com
Vice Chair, ANSI C++ Committee, X3J16
From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
Newsgroups: comp.lang.c
Subject: Re: Rounding floats to integers
Date: 12 Nov 92 03:44:26 GMT
Organization: Comp Sci, RMIT, Melbourne, Australia

In article <92314.134711IA8@psuvm.psu.edu>, IA8@psuvm.psu.edu (Alan R. Heyd) writes:
> Is there a C routine that will round off floating point numbers
> to the nearest integer.

C directly supports three ways of converting a float to an integer:

	#include <math.h>
	int i;
	double x;
	
	i = x;			/* truncate */
	i = floor(x);		/* floor */
	i = ceil(x);		/* ceiling */

Note that in the latter two, TWO conversions are involved:  double ->
integer in double format -> integer.

C does _not_ include a round-to-nearest integer function.  Many
implementations have one, but the names vary.  rint() is one of those names.

> What I do now is add 0.5 to the float before it is converted to
> an integer, for example:
>           i = 6.0 / 0.3;         /*   i = 19                     */
>           i = 6.0 / 0.3 + 0.5;   /*   i = 20 as expected         */
That isn't going to work too well for negative numbers, is it?

	double round(x)
	    double x;
	    {
		return x < 0 ? -floor(0.5-x) : floor(0.5+x);
	    }

is closer.
From: reb@quintro.uucp (Roger E. Benz)
Newsgroups: comp.lang.c
Subject: How to use make to create two different targets from the same sources
Date: 10 Nov 92 22:07:43 GMT
Organization: none

I would like to setup a Makefile that would allow me to create two
different targets from the same source files.  Our primary target is
a 68k embedded system for which we use a cross compiler.  During
development, however, we find it useful to build test version using
the native compiler.  Currently, I have to edit my Makefile to switch
compilers and then run: make clean.  If anyone knows of an easier way to
accomplish this, I would be most thankful.


-- 
Roger E. Benz              Glenayre Electronics, Inc.
Phone = (217) 223-3211     One Quintron Way
			   Quincy, IL
UUCP: tiamat!quintro!reb@uunet or quintro!reb@lll-winken
From: burch@rhps.chi.il.us (Lee Burch)
Newsgroups: comp.lang.c
Subject: Re: To Recurse or NOT to recurse?
Date: Tue, 10 Nov 92 03:17:42 CST
Organization: CrissySoft Incorporated

sjs@netcom.com (Stephen Schow) writes:

> What is better to do when traversing a linked list..... SHould I use recursio
> to search down through the list for the last node, or should I use a while
> loop?  What or the pro's and con's of each?
> 
> Thanks in advance
> -- 
   I don't mean to cut you down, but, you have not been at this
long have you...

   the overhead of making a subroutine call is actually quite high
under C, i is much faster and much perfered to use a while loop.

   the only advantage of recursion is it is easier to understand
and write than itterative mentohds.

-- Lee Burch


Newsgroups: comp.lang.c
From: mitch@nosc.mil (Ray Mitchell)
Subject: Binary Representation
Organization: Naval Ocean Systems Center, San Diego, CA
Date: Thu, 5 Nov 1992 16:02:15 GMT


It seems that since C has bitwise operators and its treatment of pointers
is so close to the underlying hardware, there should be a way of representing
constants in binary in addition to decimal, hex, and octal.  Does anyone
know why this was not done?  Maybe I'm the only one who sees any value in
it.  (Please don't tell me to use assembly if I want binary).  I've
contemplated some macro way of implementing a binary representation but
have not come up with anything reasonable.  Any ideas?

Thanks,
Ray Mitchell
Newsgroups: comp.lang.c
From: darcy@druid.uucp (D'Arcy J.M. Cain)
Subject: LHS Casting
Summary: Is it ever OK/right to have a cast on the left?
Date: Fri, 13 Nov 1992 05:00:54 GMT
Organization: D'Arcy Cain Consulting

I came across some of the ugliest code I have seen in a long time recently.
At one point there is a pointer to char that is declared as a pointer to
int.  To get an address within this block of bytes the programmer does:

(int *) charptr = intptr + (OFFSET/2);

Well of course this is bad.  The FAQ (question 2.13) shows another case
where the wrong code has the cast on the left hand side of an assignment.
Is it safe to say that there is never any case where a cast belongs on
the LHS of an assignment?  It seems to me that at best such code is
clumsy and could be better written some other way and that probably
it is wrong and the compiler is always free to reject such constructs.

-- 
D'Arcy J.M. Cain (darcy@druid.com)  |
D'Arcy Cain Consulting              |   There's no government
Toronto, Ontario, Canada            |   like no government!
+1 416 424 2871          DoD#0082   |
From: baldwin@csservera.scs.usna.navy.mil (J.D. Baldwin)
Newsgroups: comp.lang.c
Subject: Re: The Correct Way To Write C if-Statements
Date: 6 Nov 92 17:16:41 GMT
Organization: Comp. Sci. Dep't., U.S. Naval Academy, Annapolis, MD
In-reply-to: booloo@framsparc.ocf.llnl.gov's message of 05 Nov 92 18:49:33 -0400

In article <140742@lll-winken.LLNL.GOV> booloo@framsparc.ocf.llnl.gov
(Mark Boolootian) writes:
>The following piece was written by Jim Minton, an aspiring C programmer.
>I convinced him to let me post it to the net.  Happy reading and flames
>to /nev/dull...
>
>                  The Correct Way To Write C if-Statements
>                                     by
>                                 Jim Minton

Well, *I* thought it was damn funny and true besides.  I'm distribut-
ing it to my students with the caveat that if they ever mix cases in
their identifiers the way you do, I will hit them in the head with a
baseball bat.  HARD.  

Other than that, I think it's perfect.  (Well, almost: I'm a
3-space-indent man, myself, but I don't advocate the actual
imprisonment and torture of those who disagree with me by only one
space.)
--
 From the catapult of:              |+| "If anyone disagrees with anything I
   _,_  J. D. Baldwin, Comp Sci Dept|+| say, I am quite prepared not only to
 _|70|___:::)=}-  U.S. Naval Academy|+| retract it, but also to deny under
 \      /   baldwin@usna.navy.mil   |+| oath that I ever said it." --T. Lehrer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: mugsy@blakey.WPI.EDU (Michael G. Bruce)
Newsgroups: comp.lang.c
Subject: Source code needed for scanf() - or maybe you know the answer...
Date: 12 Nov 1992 02:36:00 GMT
Organization: Worcester Polytechnic Institute, Worcester, MA
NNTP-Posting-Host: blakey.wpi.edu


I want to use the read() system call in place of scanf(), for a specialized
function.  I am reading in large matrices that requires hours of input, I
hope to minimalize this time by *customizing* my own version of scanf() for
my purposes, but need to see it's implementation.

If possible please e-mail directly to me.

Thanx,
Mike Bruce
mugsy@wpi.wpi.edu


-- 
  Michael G. Bruce - mugsy@wpi.wpi.edu - Computer Science `94	      |
Sun SysAdm In Training - Electrical/Computer Engineering Dept	   -- + --
          AK211 - Computational Fields Laboratory		      |
***---***---***---***---***---***---***---***---***---***--***	      |
From: dean@cbmvax.commodore.com (Jeff Dean - LSI Test)
Newsgroups: comp.lang.c
Subject: Anyone know where I can find awkcc sources?
Date: 5 Nov 92 22:43:54 GMT
Reply-To: dean@cbmvax.UUCP (Jeff Dean - LSI Test)
Distribution: comp
Organization: Commodore Technology, West Chester, PA

I'm looking to find awkcc sources.  Anyone have them or 
know of a site?  

Thanks!
jd
-- 
==============================================================================
|   |\ /|                                               Commodore Technology |
|   'O O`   Jeffrey Dean                                   1200 Wilson Drive |
|   > v <   VLSI Test and Design Assurance            West Chester, PA 19380 |
|     ^                                            dean@cbmvax.commodore.com |
==============================================================================