HDTenEightyP/NetNews huggingface dataset:
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.lang.c,comp.lang.c++
Subject: Re: C/C++ Speed
Date: 10 Jan 93 21:59:47 GMT
Reply-To: dave@cs.arizona.edu (Dave Schaumann)
Followup-To: comp.lang.c
Distribution: usa
Organization: University of Arizona

In article <1ipsk5INNf5m@aludra.usc.edu>, dliao@aludra (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?

Probably the C program, but...

Choosing a target language *always* involves trade-offs.  C has several
advantages in its favor that tend to make C programs run faster:

  1. C is a smaller language than C++.  This means a company with $X to
     spend on developing a C compiler will have more money left over when
     it comes time to think about optimizing.

  2. C is more widely used, so more money is spent developing C compilers,
     and so the level of technology you're likely to encounter for C
     compilers is likely to be superior.

  3. C++ does have some features which might cause code to run slow.
     Since it's a more powerful language than C, it also has more features
     that can be abused.

>I just want to know if the C program will run faster than the C++ program.

Last semester, I had a graphics class, and the final project was to write
an interactive program that drew Bezier curves, with up to 50 segments.
We were allowed to choose the language, so there were people using the
(Sun 4) vendor cc, some using gcc.  I used g++ (I don't know if anyone
else did, though).  I was able to obtain very satisfactory performance
with my program.  I would even say that I was able to more easily implement
some optimizations (such as utilizing pre-computed screen coordinates)
because of the class structure available.

I realize this isn't "iron-clad proof", but my experience indicates that
unless you're really pushing the envelope, you can get competative
performance out of a C++ program.


>	I also heard the size of C++ program is generally bigger than C.

I just brought this up myself a few weeks ago.  The answer is that it is
possible to compile C++ programs to be very comparable to the size of an
equivalent C program.

On the other hand, there are some compilers out there that can generate
very large executables.

-- 
What I've learned from reading net news #2:
  Surely the most ignored phrase to be posted to the net is "'nuff said".
From: rwahbe@madrone.CS.Berkeley.EDU (Robert Wahbe)
Newsgroups: comp.lang.c
Subject: Wanted: Source for Small C Compiler for SPARC/SunOS
Date: 9 Jan 1993 00:00:32 GMT
Organization: UC Berkeley, University of California Berkeley
Distribution: world
NNTP-Posting-Host: madrone.cs.berkeley.edu

I'm looking for a small, simple C compiler for SPARC machines 
running SunOS 4.X.  I want to perform some experiments and I 
need a C (or C++) compiler that I can modify.  gcc is bigger
and more complex than I would like. lcc would be
perfect except that there is no code generator for the SPARC. 

Any ideas?

Please send email since I don't read this group.

-Robert


Newsgroups: comp.lang.c
From: bandy@netnews.jhuapl.edu (Mike Bandy)
Subject: Re: NH-- > NH
Organization: JHU/Applied Physics Laboratory
Date: Fri, 8 Jan 1993 16:24:06 GMT

In article <1993Jan4.140735.11269@wisipc.weizmann.ac.il> fedimit@wisipc.weizmann.ac.il (Dan Nabutovsky) writes:

>   Do you know that the expression NH-- > NH is always true in C ?
>The reason is that NH-- returns NH before decrementing, and then
>NH returns NH after decrementing.
>   Similarly, NH++ < NH--

So what you're saying is that NH > NH.  I don't believe it.  Your 
compiler (or your logic) has some serious problems.

-- 

	Mike Bandy
	bandy@aplcomm.jhuapl.edu
	Johns Hopkins University / Applied Physics Lab
From: volpe@bart.NoSubdomain.NoDomain (Christopher R Volpe)
Newsgroups: comp.lang.c
Subject: Re: Is that ansi ?
Date: 8 Jan 93 19:13:58 GMT
Reply-To: volpe@ausable.crd.ge.com
Organization: GE Corporate Research & Development

In article <mcdonald.28@aries.scs.uiuc.edu>, mcdonald@aries.scs.uiuc.edu (J. D. McDonald) writes:
|> In article <1993Jan8.142730.20697@osf.org> daniel@moonshine.osf.org (Daniel Dardailler) writes:
|> 
|> >A compiler is reporting the following warning:
|> 
|> >  "void * and function pointers are not convertible to each other"
|> 
|> >when encountering:
|> 
|> >       void * p = (void *) func ;   /* func of any kind */
|> 
|> 
|> I'm afraid it's true, and one of the most serious faults of ANSI C.
                                                               ^^^^^^

You mean "faults of C". This is not new to ANSI C.

|> 
|> Function pointers are orthogonal to everything else.  What you can do
|> is somehow convert them to an integer type and convert that to 
|> void * pointer and then go back. The standard itself does not 
|> guarantee that the conversion will get back the right answer however.

Huh? Function pointers can no more be converted to integers than they can
be converted into object pointers. There is nothing that says a 
function pointer will even *fit* in an integer or an object pointer.

|> (For those who need a proof, checked with Doug Gwyn, that this can be done:
|> enclose the function pointer in a struct, write out the struct to a 
|> file using fwrite, then read back in into a char array of the correct size.
|> This is guaranteed to work.) 

And how is this useful?

|> Another way is to try and use unions. This
|> is not absolutely guaranteed to work.

What are you suggesting he do with the union?

|> 
|> Doug McDonald

Daniel-
  Just change the declaration to the following:

  void (*p)() = (void (*)()) func; /* func of any kind */

-Chris

-- 
==================
Chris Volpe
G.E. Corporate R&D
volpecr@crd.ge.com
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.lang.c
Subject: Re: Where to include
Date: 8 Jan 93 04:35:25 GMT
Reply-To: dave@cs.arizona.edu (Dave Schaumann)
Organization: University of Arizona

In article <C0ID0z.504@ulowell.ulowell.edu>, vpham@cs (vinh) writes:
[format changed to save lines]

>fun() { /* ... */ }
>
>#include <stdio.h>
>
>fun2()
>
>{ printf("test..."); }
>
>we argued at work about where to put stdio.h

Put it at the top of the file.  Except for comments, #include's *always*
appear at the head of the file in my programs, and in virtually all the
other source I've ever looked at.

Besides being common practice, you should consider that programs are not
cast in stone.  fun() may not need anything from <stdio.h> now, but what
about later?  What if you add a new function that you want to put above
fun(), but needs something from <stdio.h>?  Recall that NULL is defined
in <stdio.h>, so you don't necessarily need to use an I/O routine to run
into problems.

>my co-fellow worker thinks it's ugly ; what do you think?

It's not so much ugly (IMHO) as it is a maintainence problem waiting to
happen.  I say put it at the top and leave it there.  It doesn't cost
you anything to do it, and avoids the problems I mentioned above.

>what does the standard say? what does K&R say?

This is strictly a stylistic issue.  I haven't seen the standard, but
I expect it doesn't say anything about it.  I wouldn't be surprised if
K&R doesn't say anything about it either (except by way of example).

-- 
Essentia non sunt multiplicanda praeter necessitatum -- William of Ockham
(Fact need not be multiplied beyond necessity)
Newsgroups: comp.lang.c
From: darcy@druid.uucp (D'Arcy J.M. Cain)
Subject: Re: readable code
Date: Fri, 8 Jan 1993 12:30:37 GMT
Organization: D'Arcy Cain Consulting

rorschak@daimi.aau.dk (Jesper Lauridsen) writes:
>murphy@npri6.npri.com (David P. Murphy) writes:
>>	"++x" is more readable.  [down!  down!  bad lurker! (whack) (whack)]
>I prefer "x++" myself.

Why isn't there a +x+ construct for those who can't decide?

P.S: BIG :-)

-- 
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: Ingo.Wilken@arbi.informatik.uni-oldenburg.de (Ingo Wilken)
Subject: Re: Amiga Programmers?
Organization: University of Oldenburg, Germany
Date: Tue, 5 Jan 1993 19:26:41 GMT

Hi,

david.brooks@cutting.hou.tx.us (David Brooks)  writes:
>   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.

Don't worry, with all these MS-DOG related problems that get posted to
this newsgroup, a few questions about the Amiga won't hurt anybody :-)

Ingo

-- 
Ingo Wilken, CS Student, Univ.of Oldenburg, FRG | You mean I really did all of
wilken@uniol.uucp (..!uunet!unido!uniol!wilken) | dat stuff? Now dat explains
Ingo.Wilken@arbi.informatik.uni-oldenburg.de    | why my head hurts an' why I
wilken@uniol.zer   IRC:Nobody   OL:ingo@faramir | feel so bad!  -Snarf
Newsgroups: comp.lang.c,comp.windows.open-look,alt.toolkits.xview,comp.software-eng
From: gounares@phoenix.princeton.edu (Alexander George Gounares)
Subject: apeX Announcement: Freeware developement environment
Originator: news@nimaster
Keywords: xview, openlook, hypertext, call graphs, metrics
Reply-To: gounares@phoenix.princeton.edu
Organization: Princeton University
Date: Thu, 7 Jan 1993 00:38:01 GMT

Over the past couple of months, I've seen postings in these groups
looking for X-windows software to do call-graphs, comment hiding,
file browsing, version control, etc...

Well, I've put just such a beast on export.lcs.mit.edu in the contrib
directory.  The relevant files are 
	apex.1.1.tar.Z
	apex.1.1.README

apeX includes an Object-Linking Editor, allowing text comments, audio
comments, movies, or just about anything to be "linked" to source code.
Another module allows you to follow the call tree of a program (both calls
to and calls from a function).  Yet another module interfaces to RCS...
Grab the README file (or read the manual :) for more information.

The bundle includes Sun Openwin3 binaries, so you shouldn't need to compile for that platform (it's written in XView and SlingShot, btw).

If you decide to try it, let me know what you think (even if you don't like
it).  If you really like it, well, I'm just about to graduate... :) :) :)

Enjoy!!

alex gounares
agg@cs.princeton.edu

Newsgroups: comp.lang.c
From: dkeisen@leland.Stanford.EDU (Dave Eisen)
Subject: Re: Moving from Pascal to C
Organization: Sequoia Peripherals, Inc.
Date: Sun, 10 Jan 93 00:32:23 GMT

In article <lkupqvINNnvt@exodus.Eng.Sun.COM> linden@positive.Eng.Sun.COM (Peter van der Linden) writes:
>
>From: raph@panache.demon.co.uk (Raphael Mankin)
>> IMHO the only thing one can say about pointer arithmetic is DON'T.
>
>> If your pointer points to an array, use subscripting. 
>> If your pointer is to a single item, then the only thing you should do with 
>> it is to follow it (dereference).
>
>And what if your pointer points to neither an array, nor a single item?
>But to say, a block of dynamically-malloc'd memory?

I don't agree with Raphael's advice, but he does have a point.
Many programmers don't find pointer arithmetic as natural as
array indexing and for them (or for people who have such programmers
on their maintenance staff!) his advice makes sense.

The advice is just as valid when the pointer points to a block 
of memory returns by {m,re,c}alloc as it does with an array.
You certainly can use array indexing or ordinary indirection
most of the time when using dynamically allocated memory.

>The advice above is not too surprising, coming from someone who prefers
>to hire programmers with "a degree in English or History or Physics, or 
>anything except CS."
>Maybe if you hired a few CS grad's, you'd know more about these other 
>corners of C.

This really isn't called for. I see no evidence that Raphael
is a second rate programmer. Writing readable and easily
maintainable code is important no matter how good a programmer
you are. And one can certainly make a case that pointer arithmetic
makes code more difficult to understand.


-- 
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
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.lang.c
Subject: Re: adding strings together
Date: 4 Jan 93 18:10:06 GMT
Reply-To: dave@cs.arizona.edu (Dave Schaumann)
Organization: University of Arizona

In article <83017@mavenry.UUCP>, nider@mavenry writes:
> can't you just add strings together with a +, like:
> 
> string3=string1+string2

No.

Strings in C are very low-level.  You have to call a function for virtually
every operation you want to do.  Check out strcpy() and strcat() in your
favorite language reference.  This should lead you to several other string
functions.

You should also read the chapter on pointers and arrays in _The C Programming
Lanugage_ (or any other book that discusses C).

-- 
Dave Schaumann			dave@cs.arizona.edu
From: paul@hal.COM (Paul Sander)
Newsgroups: comp.lang.c
Subject: Re: strtok
Date: 4 Jan 93 21:43:38 GMT
Distribution: usa
Organization: HaL Computer Systems, Inc.
NNTP-Posting-Host: parlo.hal.com

In article <bibhas.725836376@femto.engr.mun.ca> bibhas@femto.engr.mun.ca (Bibhas Bhattacharya) writes:
>tjhendry@mcs.drexel.edu (Jonathan Hendry) writes:
>
>>Hi. Could someone please email me a brief description of how to use
>>strtok()? I have read a few books, and asked my coworkers, and haven't
>>received much useful information.
>
>>Namely, after I run it on a string once, how do I get to the next
>>part of the string?
>
>It's worth noting that the string returned by strtok is not a fresh copy
>but a part of the fragmented original string. Which means:

[example deleted]

It's also worth noting that strtok keeps global state, which means that it
is not reentrant.  Since strtok is usually used for some kind of loop variant,
you must be careful never to call strtok again from inside the loop.  When
your loop calls another function that calls another function that calls
strtok, you have a bug that is quite difficult to track down.

Robert Osborne posted a strtok replacement to comp.lang.c on September 12,
1991 that returns strtok's global state in a parameter to the caller, making
it reentrant.  The message-ID is 1395@isgtec.UUCP, and I have copies of it
if anyone is interested.
-- 
Paul M. Sander  (408) 379-7000  |  "If everything were easy, where would be
HaL Computer Systems, Inc.      |   the challenge?"
1315 Dell Avenue                |
Campbell, CA  95008  USA        |
Newsgroups: comp.lang.c
From: johnvl@dutecaj.et.tudelft.nl (John C.M. van Leeuwen)
Subject: Re: realloc (again)
Keywords: Realloc
Organization: Delft University of Technology, Dept. of Electrical Engineering
Date: Tue, 12 Jan 1993 15:07:45 GMT

In article <C0pGL7.GqI@compsci.liverpool.ac.uk>, scst81@csc.liv.ac.uk (Mr. I. Rowland) writes:
> Following my last communication I developed another smaller program that
>   uses REALLOC in the same way as my other code:
> 
>   #include <stdio.h>
>   #include <stdlib.h>
>   #include <string.h>
> 
>   #define noofstr 5
> 
>   #define bufsiz 255
> 
>   void main (void)
> 
>   {
>           char *array; char buff[bufsize];
>           int i;
>           int bytes ;
> 
>           for (i=0; i < noofstr; i++)
>           {
>                   printf("Enter string %d : ",i);
>                   scanf("%255s",buff);
>                   bytes = strlen(buff)+1;
>                   array = reilloc(array, (bytes));
> 
>                   if (array== NULL)
>                   {
>                           printf("Can't allocate");
>                           exit(1);
>                   }
>           strcat (array,buff);
>           }
> 
> 
> 
>                   printf(array);
>   }

In the manual I read: the pointer passed to realloc()  (here: array)
has to be initialised before using one of the normal allocation functions.
So try:
           char *array = "";

at the beginning instead. I guess you'll get rid of those ugly messgaes this way
.

John van Leeuwen.  (j.c.m.vanleeuwen@et.tudelft.nl)
Newsgroups: comp.lang.c
From: agrafiot@wl.com (Dimitris Agrafiotis)
Subject: question on casting unions
Organization: Warner Lambert / Parke-Davis
Distribution: usa
Date: Wed, 6 Jan 1993 16:02:58 GMT


I have the following question regarding unions. Assume that 'un' is defined
as follows:

union
{
   char a;
   long b;
}
un;

Can one refer to un.a and un.b by ((char) un) and ((long) un), respectively?
Thanks

-- 
Dimitris K. Agrafiotis
Computer Assisted Drug Design
Parke-Davis Pharmaceutical Research
(agrafiot@wl.com)
Newsgroups: comp.lang.c
From: zoltan@research.canon.oz.au (Zoltan Kocsi)
Subject: Re: The 2-Dee Array Deelemna
Originator: zoltan@radics
Organization: Canon Information Systems Research, Australia
Date: Mon, 11 Jan 1993 01:31:15 GMT

In article <1993Jan6.190355.9632@nsisrv.gsfc.nasa.gov> almeida@ame.gsfc.nasa.gov (aswin m. almeida) writes:

    [ text deleted ]
    
    for (i=0; i<10; i++)
     for (j=0; j<nrows; j++)
     {
       printf("%d x %d = %d\n",i,j,i*j);
       array[i][j] = i*j;   /* dbx reports this as the location of the bus error */
       printf("%d,%d = %d\n",i,j,array[i][j]);
    [ text deleted ]

   1) The reason I am getting this annoying bus error.
   2) An explanation, with crude ASCII pictures, of *, **, and & in C.
   3) An explanation of why | array[i] = (int *) malloc (ncolumns * sizeof(int));

1) The bus error is caused by wrong order of indices, your array
   ( with the given input ) is array[ 3 ][ 10 ] as you have an array that
   has nrows elements containing nculumns ints each.

2) and 3) In the memory it looks like this:

   --------------		
   | array      |--+            |           |	
   --------------  |            -------------
   :            :  :            |array[0][9]|
   --------------  |            -------------
   | array[0]   |<-+            :           :
   --------------\              -------------
   | array[1]   |-\------------>|array[1][0]|
   --------------  |            -------------
   | array[2]   |--+--+         |array[1][1]|
   --------------  |  |         -------------
   :            :  :  |         |           |
   --------------  |  |         -------------
   | array[0][0]|<-+  |         |array[1][9]|
   --------------     |         -------------
   | array[0][1]|     |         :           :
   --------------     |	        -------------
   |            |     +-------->|array[2][0]|


Zoltan
-- 
Zoltan Kocsi <zoltan@research.canon.oz.au>
Newsgroups: comp.lang.c
From:  stas@itco.msk.su (Stas Strizhakov)
Subject: Arrays with variable dimensions?
Date: Tue, 5 Jan 1993 17:25:47 GMT
Reply-To: stas@itco.msk.su
Organization: I.T. Co., Moscow, Russia.

In article <1992Dec26.220736.22177@news.ysu.edu>
Subject: [NEWS] Arrays with variable dimensions?
ah017@yfn.ysu.edu (John B. Lee) writes:

>Is it possible to create an array that would change size according
>to user input?

        May be try to use *alloc/realloc pair.

For example,

void main () {
        int size; int *ar; int *newAr;
        size = 1; ar = malloc (size*sizeof(int));
        while (size++ < 1000) {
                newAr = realloc (ar, size*sizeof(int));
                if (newAr != NULL) ar = newAr;
        }
        free (ar);
}

        I used this method when wrote editor with automatically
extending buffer

--

					Regards,
								Stas.
???????????????????????????????????????????????????????????????????????????????
						There's so many different worlds
						So many different suns
Stas K. Strizhakov				I.T.Co				Programmer
phone	: (7-095)262-4381		fax 	: (7-095)924-3775
e-mail	: stas@itco.msk.su
Newsgroups: comp.lang.c
Subject: Re: applying or
From: a_rubin@dsg4.dse.beckman.com (Arthur Rubin)
Date: 8 Jan 93 16:57:58 GMT
Organization: Beckman Instruments, Inc.

In <1993Jan06.002044.795@microsoft.com> russpj@microsoft.com (Russ Paul-Jones) writes:


>So, there are some instances where this optimization might be made:

>b = 4;
>if (a*7)/3 > 100/a || b
>	fred();

>I would say that fred() may be called without evaluating the silly 
>expression, even if a == 0.  But I would suspect that it would take 
>a fairly clever compiler to safely find many of these instances.

I don't think so.  (Well, in this example, it's permitted, as the
expression has no side effects except divide-by-0, the results of which are
undefined, but...)

b = 4;
if (a*7)/3 > 100/a++ || b
	fred();

is a different matter.

--
Arthur L. Rubin: a_rubin@dsg4.dse.beckman.com (work) Beckman Instruments/Brea
216-5888@mcimail.com 70707.453@compuserve.com arthur@pnet01.cts.com (personal)
My opinions are my own, and do not represent those of my employer.
My interaction with our news system is unstable; please mail anything important.
Newsgroups: comp.lang.c
From: dfuller@portal.hq.videocart.com (Dave Fuller)
Subject: Re: Hex escaping in strings, (porting from gcc to cc)
Organization: VideOcart Inc.
X-Newsreader: Tin 1.1 PL3
Date: Tue, 5 Jan 1993 23:13:44 GMT

chrisp@grace.cri.nz writes:
: Hi,
:   I have a problem with porting from gcc to cc (on a sun sparc station)
: 		
: 	puts("\x1b=");		/* set's the terminals keypad mode */
: 
:  Works fine with gcc, the "\x1b" is interpreted as ascii 27, escape.  But
:  on cc it just prints "x1b=".
: 
:  Is the hex code escape an ansii extension,  how else can I do it?, I would
:  rather avoid:
: 	sprintf(tmp,"%c=",27);
: 
: 				Thanks,  Chris.	   chrisp@grv.grace.cri.nz

   You'll have to forgive me, i dont use gcc, and i dont keep track of
the ANSI standard very well. What you have here is probably an extension 
of gcc. The \ is used to escape n b t and a. Maybe others. It would appear
that gcc added x as an escape for translating hex codes. What you need to
do to make this work is to change the x1b to its octal value. This is 
understood in ANSI C. 

so puts("\x1b=")  ---->>>   puts("\033=")

to put multiple escape chars together it would be puts("\033\033=");

you get the point.

chars may be represented as octal values when initialized.

char ch_1 = 'X',
     ch_2 = '\130',
     ch_3 = 0130;

gives the same value to all of the char variables.


Dave Fuller
dfuller@portal.hq.videocart.com


Newsgroups: comp.lang.c