HDTenEightyP/NetNews huggingface dataset:
From: chuckb@stein.u.washington.edu (Charles Bass)
Newsgroups: comp.lang.c
Subject: Re: Question to test general C knowledge
Date: 18 Dec 92 07:07:47 GMT
Organization: University of Washington

How about some of these as interview questions:

1) What portability problems have you had specific to C and how
did you "fix" them?

2) Have you ever had numerical difficulties in a program?  If so
what measures have you taken to prevent them from occuring
again?

3) What situtations in C is recursive programming a positive?
Negative?

4) Do you use a profiling tool?  If so when? When not? 

5) What case tools have you used?  Why did you choose it over
another competitors?

6) What elements would you put in a structure used for a doubly
linked list?  Write it out? 

7) When are externs used? Why do people use the following construct?
#ifndef HEADER_XXXX
#define HEADER_XXXX

< header_stuff >

#endif

8) Show me some of your code that you think is nice.  Why is
it nice code?  If you rewrote it what changes would you make?

These questions might not be appropriate in all cases and in
some ways they assume the applicant has knowledge of C and must
answer the questions with such assumptions in mind.

Answers to these questions should give a good idea to the
knowlege of an applicant.  They slant towards larger projects.

These questions put the pressure on the interviewer because
instead of sending an applicant off because they couldn't name
four NULLs or what "adsfads"[4] means they must access applicants
knowledge from answers that actually pertain to programming in
a "real" job. (not that I know anything about a *real* job ;-)

It also might be beneficial to lead an applicant because of
nervousness or whatever.  There probably are some shy
programmers out there...
 
I'd hate to miss out on a job because I thought [4]"asdf" wasn't
a legal C statement.

chuckb
From: ele@chama.eece.unm.edu
Newsgroups: comp.lang.c
Subject: Questions about token merging and trigraphs
Date: 11 Dec 92 16:35:41 GMT
Distribution: world
Oranization: University of New Mexico


Two questions about ANSI C:

(1) How is the preprocessor token merging mechanism (##) supposed to
be used?  I know, for example that if you have

#define X(i)  x ## i

then the preprocessor will replace code like 'X(1)' with 'x1', but
could someone give me an example of where this (or some other use of
'##') would be useful?

(2) There is a command-line switch to disable the 'trigraph' feature
in the gcc compiler.  What are trigraphs?  From the comments in the
gcc documentation I gather that they are something that the ANSI
committee has added to C and that Richard Stallman doesn't care for
them.  If that is the case, I'm wondering what purpose the ANSI
committee saw for them, why anyone would object to them, and, most
importantly, what they are.

Thanks for any help offered!

--
  Erik L. Ellis                 |
  NASA Langley Research Center  |  Office:  804/864-5819
  Information Systems Division  |    Home:  804/827-1259 (leave msg.)
  Mail Stop 152D                |     FAX:  804/864-8672
From: torek@horse.ee.lbl.gov (Chris Torek)
Newsgroups: comp.lang.c
Subject: Re: difference between a typedef structure and a structure tag?
Date: 14 Dec 1992 03:02:18 GMT
Organization: Lawrence Berkeley Laboratory, Berkeley CA
NNTP-Posting-Host: 128.3.112.15

In article <1992Dec9.121415.13964@cs.utwente.nl>
ahoekstr@cs.utwente.nl (Andre D. Hoekstra) writes:
>Ok, now *I* am puzzled [as to the reason that structure tags and typedefs
 both exist]

>From the latter remark, must I conclude that both are legal and sane C?
>That would bring us back to the first question: why?

Historical answer:  struct/union tags predate typedefs.

Technical answer:  tags are required for forward references (whether
using typedefs or not).

Stylistic answer:  typedefs are syntactically obnoxious (given the line

	register foo_type;

do we have an empty declaration, or a declaration of an int called
`foo_type'?  That depends on whether foo_type has been typedef'd).

To expand a bit on the technical answer: as John Woods pointed out in
some article whose referent seems to have been dropped:
>>Structure tags are required when you need recursive structures, e.g.
>>	struct obj {
>>		struct obj *o_next;
>>		/* stuff */
>>	};

Note that even with a typedef, the tag is still required:

	typedef struct obj obj_t;
	struct obj {
		obj_t	*o_next;
		/* etc */
	};

This holds even if `obj_t' is made into a pointer type, e.g.,

	typedef struct obj *obj_t;

Furthermore, tags are required in order to `clear out' a previous
outer-scope structure definition:

	struct obj;	/* remove outer-scope structure, if any */
	struct obj { ... };
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)
Berkeley, CA		Domain:	torek@ee.lbl.gov
From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
Newsgroups: comp.lang.c
Subject: Re: Test for general 'C' knowledge
Date: 17 Dec 92 22:02:34 GMT
Organization: McGill Research Centre for Intelligent Machines

In article <1gj0n5INNjut@uwm.edu>, pegasus@csd4.csd.uwm.edu writes:

> I have been reading the many questions that some employers ask
> potential hirees with a sinking feeling in my stomach.

> I consider myself a fairly comptetent 'C' programmer for only using
> the lanquage for about 2 years.  After reading these questions I
> realized that I could only answer them half way.

> Does this mean that I am not a competent programmer?

No.  Given the questions, though, it means you would not be a competent
language lawyer.  Don't let it bother you; few people are.

> AM I less of a programmer if I have to look up QuickSort in a
> reference book?  I was taught in school that it is not neccessary to
> memorize any type of sort.

Less of a programmer?  Yes, of course.  Significantly less?  I would
say not.

> About the question:   i = i++
> WHo the heck would write that anyway?

You shouldn't.  The problem is that you may get handed old code to port
or otherwise maintain, and find that it uses such horrors.  (This is
the only excuse I've been able to think of for anyone to bother
understanding more about that construct than why it's undefined.)

> How would I go about acquiring knowledge like this?

Read the net.  Carefully. :-)

> I am just wondering because I would hate to apply for a job and be
> told that I am incomptent because of questions like these.

You probably don't want to work for a place that wants every programmer
to be a language lawyer.  Unless you *are* gunning for a language
lawyer position, in which case, study, study, study...study existing
code, study all different implementations you can find, study the
Standard....

					der Mouse

			    mouse@larry.mcrcim.mcgill.edu
Newsgroups: comp.lang.c
From: mccall@mksol.dseg.ti.com (fred j mccall 575-3539)
Subject: Re: Another question to test general C knowledge
Organization: Texas Instruments Inc
Date: Tue, 15 Dec 1992 17:28:09 GMT

In <1992Dec15.131413.3057@infonode.ingr.com> dfw@fed_img.ingr.com writes:

>Yeah,
>  how about

>  i = i++;

>  What are the side effects of THIS (i never gets incremented).
>  i = ++i; is trivial; ++i PRE-increments i, then assigns it to itself,
>  just as i++ or i += 1.

Well, either someone isn't paying attention, or they just like to
start long threads.  It's undefined.  Probably could spindle your cat
or pleat the dog or something.

-- 
"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: Jon Freivald <jaf@jaflrn.UUCP>
Newsgroups: comp.lang.c
Subject: Re: How to run a program from another program using Turbo C??
Date: Sun, 13 Dec 92 01:48:45 EST
Organization: The Wizzard's Cave, East Meadow, NY

Mike.Tedder@f181.n363.z1.fidonet.org (Mike Tedder) writes:

>   printf("\nShelling to DOS...\n");
>   spawnlp(P_WAIT,"COMMAND.COM",NULL);

Ah!  You are one of the many culprits -- I don't use, and don't like
command.com!!!  Please do the following instead:

                spawnlp(P_WAIT,getenv("COMSPEC"),NULL);

In this manner, I get my native (& much nicer) command interpreter!!!

Jon

=============================================================================
		   Jon Freivald ( jaflrn!jaf@uunet.UU.NET )
	 Nothing is impossible for the man who doesn't have to do it.
=============================================================================
From: gcouger@olesun.okstate.edu (Gordon Couger)
Newsgroups: comp.lang.c
Subject: Re: a question about if and case
Date: 15 Dec 92 00:51:43 GMT
Article-I.D.: osuunx.1992Dec15.005143.10180
Organization: Oklahoma State University, Stillwater

In article <Bz9H6p.DrB@netnews.jhuapl.edu> bandy@netnews.jhuapl.edu (Mike Bandy) writes:
>"hans friedrich steffani" <GM08@DKAUNI2.BITNET> writes:
>
>>int i;
>
>>if( i == 1 || i == 25 || i == 125 )
>> {
>>switch( i )
>> {
>>  case 1:
>>  case 25:
>>  case 125:
>>  /* do something sophisticated */
>>  break;
>IMHO people worry about this sort of thing too much.  The important thing
>is to develop a strong *maintainable* style.  The performance differences
>are insignificant, so do what you thing works best.
 If you are writing some bookkeeping program maybe but slow code accumulates.
Try writing a graphics routine or somthing that is in a loop that runs for
4 days and slow code will show up. 
IMHO if you get in the habit of writing fast code and maintainable code you
 are better off. 
I realize I come from a different angle than most programmers. I work mostly
with embeded systems. where speed is king.

Gordon Couger
AB5Dg   Agriculture Engineering Oklahoma State University
gcouger@olesun.agen.okstate.edu 405-744-6514 day 744-2794 evenings   
Newsgroups: comp.lang.c
From: jutta@opal.cs.tu-berlin.de (Jutta Degener)
Subject: Re: Pointer to Function Question
Organization: Techn. University of Berlin, Germany
Date: Tue, 15 Dec 1992 15:39:04 GMT

This has little to do with pointers to functions; it's only the
structure-tag-with-prototype-scope question again.   (Sorry if
it's already in the FAQ -- haven't found it.)

curry@hplred.HPL.HP.COM (Bo Curry) writes:
> typedef struct {
>	void (* displayit)(struct _WINDOW *);
> } DISPLAYTYPE;
>
> static void ShowMyPanes(struct _WINDOW *);
>
> int Testit ()
> {
>	DISPLAYTYPE mypanes;
>	mypanes.displayit= ShowMyPanes;
>	...
> }

If you use `struct _WINDOW *' in your code without a previous 
declaration of the same thing in the enclosing scope, you 
`declare a new structure tag'.  The scope of a declaration
(the part of your code it affects) depends on where you write it.
If you declare a structure inside of a prototype declaration

	static void ShowMyPanes(struct _WINDOW *) ;

its scope is only the parameter list of the prototype declaration.
The two "struct _WINDOW *"s in 

	static void afunc(struct _WINDOW *);
	static void bfunc(struct _WINDOW *);

need not have anything to do with each other; and neither
do those in your example.

You fix this by writing 
	
	struct _WINDOW;

before the declarations in the enclosing scope; this "starts a new
scope".  From that point, all "struct _WINDOW"s you use will refer to
that first one, unless you explicitly tell the compiler that you'll
be talking about a new one -- again using

	struct _WINDOW ;

Jutta Degener (jutta@cs.tu-berlin.de)
Newsgroups: comp.lang.c
From: "peter curran" <peter.curran@canrem.com>
Subject: Re: Questions about token merging and trigraphs
Reply-To: "peter curran" <peter.curran@canrem.com>
Organization: Canada Remote Systems
Distribution: comp
Date: 20 Dec 92 08:51:55 EST


kdq@quest.UUCP (Kevin D. Quitt) writes (in part) ...

KD>    I believe I've shown that your first adjective is incorrect,
KD>and your second is questionable.  As to harm, no code was broken;
KD>the only thing that changed was the appearance of some output -
KD>and you've yourself indicated that is of no great harm.

That is not true - as Dr. Andrews showed (an no doubt others could),
some code was broken.  Whether the damage to the code was serious
or not, no one but the authors and users of that code can determine.
Certainly, as several people have pointed out, the problem is
easily fixed, *once the cause is understood*.  That is the hard part,
since many people have never heard of trigraphs.

However, the question that the committee had to face was, does the
benefit of trigraphs outway the costs.  They decided, correctly IMHO,
that it does.  I believe that ISO could never have accepted the C
standard without them (or something similar).  That would have
meant that ISO would have produced a modified standard, and once
modifications had started, there is no telling where they would
have stopped.  We would have ended up with one standard for the US,
and a second, perhaps substantially different one, everywhere else.
The cost of that would have far exceed the cost of fixing a few
programs broken by trigraphs.

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
From: bhoughto@sedona.intel.com (Blair P. Houghton)
Newsgroups: comp.lang.c
Subject: Re: Help!!!!!!!!!!!!
Date: 14 Dec 1992 21:40:49 GMT
Organization: Intel Corp., Chandler, Arizona
NNTP-Posting-Host: alfalfa.intel.com

In article <1992Dec14.174931.4650@rexago8.uucp> aa@rexago8.uucp (Adam Andrews) writes:
>jcontro@engws10.ic.sunysb.edu () writes:
>>   SOME_STUCT  *Ptr;
>>fn( ..., Ptr );
>
>Try passing it like: fn( ..., &Ptr);
>and receiving it like: fn ( SOME_STRUCT **Ptr) { ...

Try having fn() create the list from whole cloth
and return the list:

    typedef struct ... SOME_STUCT;

    ...
    {
	SOME_STUCT  *Ptr;
	...
	Ptr = fn();			/* gimme da list */
	...
    }

    /* just a little OOP */
    SOME_STUCT  *new_stuct( void )
    {
	SOME_STUCT  *new;

	new = (SOME_STUCT  *) malloc ( sizeof(SOME_STUCT) );
	if ( !new ) {
	    ...				/* barf and die */
	}

	new->foo = NULL;		/* zero members appropriately */
	new->bar = 0;
	new->bazz = 0UL;
	...
	new->next = new->prev = NULL;

	return new;
    }

    SOME_STUCT  *fn( void /* or other data needed to fill the list */ )
    {
	SOME_STUCT  *new, *p;

	if ( ... )
	    return NULL;		/* have nothing to list */

	new = new_stuct();

	...				/* fill first member of list */

	p = new;

	while ( ... ) {
	    p->next = new_stuct();
	    p = p->next;
	    ...				/* fill subsequent member of list */
	}

	return new;
    }


It's practically an idiom, and it runs a heck of a lot
faster than you think on most hardware.

				--Blair
				  "What's a 'stuct'?"
Newsgroups: comp.lang.c
From: chelf@lunatix.uucp (Chad Helfenberger)
Subject: Turbo C with built-in assembler??????
Organization: Lexington Public Access Unix. -KY- (606) 255-9121
Date: Wed, 16 Dec 1992 22:07:42 GMT

I seem to have gotten a bad copy of Turbo C++ (v3.0).  On the _box_, it says 
'built-in assembler' along with the other 'features'.  However, when I try 
to compile a program with inline asm code (as in #pragma inline), it aborts 
with 'TASM not found'.  Any insight on this?  If it has a built-in 
assembler, why would it be trying to call tasm?  

Another question.  The manual that came with it is very sparse, and doesn't 
list the function call prototypes or *anything*.  All it is, basically, is a 
guide to use the stupid integrated environment (which is nice as a debugger, 
but NOT an editor).  I know the online help provides all this, but I'd 
rather have a book that I can use, WHILE I'm in my favorite editor.  :) 

Thanks for any help!!

-- 
Chad Helfenberger
(chelf@lunatix.uucp) 
Newsgroups: comp.lang.c
From: dat@thinkage.on.ca (David Adrien Tanguay)
Subject: Re: longjumping out of a signal handler
Organization: Thinkage, Ltd.
Date: Thu, 17 Dec 1992 12:10:37 GMT

tye@spillman.uucp (E. Tye McQueen) writes:
>K&R II doesn't talk about any of this and my copy of the standard
>is way outdated, so maybe I'm wrong; but I distinctly recall that
>ANSI guarantees only two things that can be done within a signal
>handler:  1) Set a variable of type "sig_atomic_t"  and  2) Call
>longjump().

ANSI 4.7.1.1
	If the signal occurs other than as a result of calling the abort or
	raise function, the behaviour is undefined if the signal handler calls
	any function in the standard library other than the signal function
	itself (with a first argument of the signal number corresponding to
	the signal that caused the invocation of the handler) or refers to
	any object with static storage duration other than by assigning a
	value to a static storage durection variable of type volatile
	sig_atomic_t.

You cannot portably call longjmp from a signal handler (modulo abort/raise).
-- 
David Tanguay       dat@Thinkage.on.ca  dat@Thinkage.com  uunet!thinkage!dat
Thinkage, Ltd.           Kitchener, Ontario, Canada          [43.40N 80.47W]
From: david.brooks@cutting.hou.tx.us (David Brooks) 
Newsgroups: comp.lang.c
Subject: WHAT WENT WRONG?
Date: 16 Dec 92 05:21:00 GMT
Distribution: world
Organization: The Cutting Edge - Houston, TX - 713-466-1525
Reply-To: david.brooks@cutting.hou.tx.us (David Brooks) 

The following code is intended to compute the factorial of a given
number. Unfortunately it gives weird results for numbers larger than 12
or so... Does anyone have an idea why? I tried compiling it under Huge
memory model and still the same effects.


#include <stdio.h>

main()
{
    double x, y;

    printf("\nEnter number to factorialize:");
    scanf("%d", &x);

    for(y=x-1;y>1;y--) x*=y;

    printf("\nFactorial= %d\n", x);
}


Undoubtedly the problem comes from playing with numbers that are too
big. Is there something obvious that I am overlooking here? Or is there
some hidden secret for dealing with big numbers that only rocket
scientists and C gurus are aware of? Any help is appreciated!

   David
                                                   
----
+---------------------------------------------------------------------+
| The Cutting Edge BBS (cutting.hou.tx.us)    A PCBoard 14.5a system  |
| Houston, Texas, USA    +1 713 466 1525          running uuPCB       |
+---------------------------------------------------------------------+
From: u-mwong%peruvian.cs.utah.edu@cs.utah.edu (Michael Wong)
Newsgroups: comp.lang.c
Subject: SWITCH Statement Question
Date: 15 Dec 92 19:24:55 GMT
Distribution: usa
Organization: University of Utah CS Dept


   I have a question regarding the SWITCH statement in C.  I'm having
conflicting answers from people at work and need some help.  How does the
SWITCH statement process the CASE statements?  It's not clear to me how
it works internally.  The following example will help clarify my question...

   Will using a SWITCH statement run faster if it had few CASE statements and 
IF statements were used to aid in the processing than using a SWITCH 
statement that had a very long list of CASE statements.  In other words, 
compared to:

switch (key)
{
  <50 CASE statements here>
}

would this following code be faster, if the SWITCH was broken down using IFs:

if (...)
{
  switch (key)
  {
    <10 CASE statements here>
  }
}
else if (...)
{
  switch (key)
  {
    <10 CASE statements here>
  }
}
else if (...)
  <more SWITCH statements>


   I'm worried about speed, but I also want to keep the code easy to
understand.  I'd appreciate if someone could tell me exactly how SWITCH
works internally!

-Mike
----------
Michael Wong 
u-mwong@peruvian.utah.edu
University of Utah
Newsgroups: comp.lang.c,comp.lang.c++,comp.lang.pascal
From: mslyz@congeries.engin.umich.edu (Marko J Slyz )
Subject: signal.h help
Date: Sat, 19 Dec 92 01:47:56 EST
Organization: University of Michigan Engineering, Ann Arbor
Originator: mslyz@congeries.engin.umich.edu


The following program was written for an HP9000/700 and compiled
with:  c89 -ot1 t1.c -lm

It compiles with no errors or warnings.
-----------------------------------------------------
#include <stdio.h>
#include <signal.h>

extern int errno;

main()
{
  double x,y;

  y = 0.0;  /* sic */

 if (signal(SIGFPE,SIG_IGN) == SIG_ERR)
    printf("couldn't set up new signal handler\n");

  x = 100.0/y;

  printf("x = %.15g\n", x);
  printf("(char)x = %d\n",(char)x);
}

-----------------------------------------------------

When run as shown above it prints
x = ++

and then hangs. ^C will recover (but not just a CR). If you
leave out the "if" statement it says

x = ++
Floating exception (core dumped)

I've tried writing my own error handler and that doesn't help.
Any ideas?

Thanks in advance,
Marko
Newsgroups: comp.lang.c
From: ddunlap@boi.hp.com (Doug Dunlap (DTC))
Subject: TSR in Turbo C
Summary: simple TSR in Turbo C
Date: Mon, 14 Dec 1992 15:25:41 GMT
Organization: Hewlett-Packard / Boise, Idaho
X-Newsreader: TIN [version 1.1.9 PL6]
Keywords: tsr,turbo

  I would like to write a simple TSR in Turbo C.  Could anyone give
  me some helpful hints or code fragments?  I want to be able to 
  blast a date-time string onto a line with a keystroke.

  Thanks,
  Doug Dunlap

 ==============================================================================
 ==  Doug Dunlap   (208)323-6257              =========    _/         =========
 ==  ddunlap@boi.hp.com                       ========    _/           ========
 ==  Hewlett-Packard                          ======     _/_/_/  _/_/_/  ======
 ==  Distributed Technical Computing          ======    _/  _/  _/  _/   ======
 ==  Mail Stop 1110                           ======== _/  _/  _/_/_/  ========
 ==  11311 Chinden Blvd                       =========       _/      =========
 ==  Boise,  ID  83714-1021                   ===========    _/     ===========
 ==============================================================================
From: andrewr@infoware.co.za (Andrew Roos)
Newsgroups: comp.lang.c
Subject: Re: fork() and wait() problem...Please HELP!
Date: 15 Dec 92 09:30:50 GMT
Organization: Infoware (Pty) Ltd

newton@wilbur.psu.edu (Cynthia Newton) writes:

>In the following  program, if I want to edit the file more than than
>once, most of the time 'vi' just freezes.

>Could you tell how to handle this kind of situation correctly?
>I don't want to use system().

>I use SunOS 4.1.1

>Thanks.

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

>main()	{
>	int pid;
>	int ch;

>for(;;){
>	ch=chh();
>switch(ch)
>{
>	case 1:
>	pid=fork();
>	if(pid==0){
>	execl("/usr/ucb/vi","vi","file",NULL);
>}
>wait();
>break;
>	case 2:
>	exit();
>}
>}

>}

>chh()
>{
>int c;
>char s[10];
>fprintf(stderr,"1. edit\n");
>fprintf(stderr,"2. exit\n");

>do{
>fprintf(stderr,"Enter Choice: ");
>gets(s);
>c=atoi(s);
>}while(c<0 || c>2);
>return c;
>}
>--------------------------------------
>-- 
>C Newton

Hi Cynthia

I don't know if this is the problem, but your call to wait() is incorrect.
Wait expects a pointer to int as an argument, which is where it stores the
status of the child process which terminated. You can modify it to:

wait((int*)0)

if you are not interested in the status. It is possible that the status
value is being written to an arbitary address which may be corrupting 
something. 

Hope this helps

Andrew Roos
From: dw3u+@andrew.cmu.edu (Daniel C. Wang)
Newsgroups: comp.lang.c
Subject: Re: Question to test general C knowledge
Date: 12 Dec 92 13:24:42 GMT
Article-I.D.: andrew.8f_bGuK00aw3At0FV2
	<1992Dec11.214128.1136@nb.rockwell.com>
Organization: Freshman, MCS general, Carnegie Mellon, Pittsburgh, PA


wade@nb.rockwell.com (Wade Guthrie) writes:
> One question that I particularly like, although few applicants ever get it, is:
> 
> what does:
> 
>  printf("shop"+1); 
> 
> do?
> 
> Wade
> wade@nb.rockwell.com

hop 

"shop"+1 is the address of the string constant "shop" plus one. So
printf gets "hop";

Am I hired? :) 
Newsgroups: comp.lang.c