HDTenEightyP/NetNews huggingface dataset:
From: chuckb@stein.u.washington.edu (Charles Bass)
Newsgroups: comp.lang.c
Subject: Re: a question about if and case
Date: 15 Dec 92 04:50:42 GMT
Organization: University of Washington

>GM08@DKAUNI2.BITNET (hans friedrich steffani) writes:
>> i have something like
>> 
>> int i;
>> 
>> if( i == 1 || i == 25 || i == 125 )
>>  {
>>   /* do something sophisticated */
>>  }
>> if( i == 2 || i == 30 || i == 244 )
>>  {
>>   /* do something different */
>>  }
>> 
>> or should i use
>> 
>> switch( i )
>>  {
>>   case 1:
>>   case 25:
>>   case 125:
>>   /* do something sophisticated */
>>   break;
>> 
>>   case 2:
>>   case 30
>>   case 244:
>>   /* do something different */
>>   break;
>> 
>>   default:
>>   break
>>  }
>> 
>> or is there a third way??
>> i need contructions like this very often so i need a GOOD
>> solution.
>> 
>> hans friedrich   steffani@imbaibrs1.bau-verm.uni-karlsruhe
>> steffani         gm08@rz.uni-karlsruhe.de
>>                  gm08@dkauni2.bitnet

>The first way is more readable the second probably marginaly faster
>during compile time.  Can't think of a third way off hand that would
>be worth mentioning.  I'd stick with readablity over 'speed.'

In my opinion the code with the case is more readable because
I use the case construct often.  So I would use case.  If speed
were definitly the issue I would profile the code and see.  The
difference is likely to vary between machines and compilers not
to mention possibly the values used in the case (if I recall
information from someone's previous post on this group).  At any
rate the rule of thumb should be readable code first and if the
profiler shows a bottleneck go fix that code.  It's also a good
idea to comment drop-thru's in a case statement.

chuckb
From: rankin@eql.caltech.edu (Pat Rankin)
Newsgroups: comp.lang.c
Subject: Re: Questions about token merging and trigraphs
Date: 19 Dec 1992 19:53 PST
Organization: California Institute of Technology
Distribution: world
NNTP-Posting-Host: eql10.caltech.edu
Summary: time to worry about digraphs, not trigraphs
Keywords: trigraph digraph
News-Software: VAX/VMS VNEWS 1.41    

     There's not much point arguing about trigraphs now, so long after
the fact.  They cannot be removed until 1999 at the earliest.  However
there is apparently a similar issue which is currently relevant:  the ISO
committee's consideration of adding _digraphs_ (not to replace trigraphs,
but in addition to them).  My only information is hearsay and comes from
assorted postings in this group and/or comp.std.c.

In article <XZo2VB1w165w@quest.UUCP>, srhqla!quest!kdq writes...
[ lots of text deleted; this is reportedly a direct quote from the
  ANSI rationale document, which is not part of the actual standard: ]
> "...The obvious idea of defining two-character escape sequences fails
> because C uses all the characters which _are_ in the ISO 646 repetoire:
> no single escape character is available.  The best that can be done is
> to use a _trigraph_ - an escape digraph followed by a distinguishing
> character."

     Apparently [a majority of?] the current members of the ANSI committee
don't agree with that any more, if the report that they've decided to stop
actively opposing digraphs is accurate.  If the proposed set of digraphs
affects string literals--I'm not sure, since I don't have all the phases
of compilation memorized, nor a list handy--then at least one of them is
certain to cause problems under VMS.  Angle brackets ("<",">") are valid
alternate delimiters for directory names--inherited from TOPS-10 or TOPS-20,
precisely because the normal square bracket ("[","]") delimiters are not
available on some non-ASCII terminals and printers--and *printf format
strings which reference "<%" (proposed digraph for "{") do exist.  Consider
        sprintf(file_specification, "%s:<%s>%s.%s;%d",
                device, directory, basename, filetype, version_number);
or the analogous *scanf call for picking a fully-qualified name apart.
I imagine some Unix programs which construct command strings for system()
have similar occurances of "<%s" for redirecting the standard input stream.
This would not be a relatively harmless affect on message text, but a major
breakage for some small but non-zero pecentage of code.  Of course if
digraphs don't apply to string literal processing then this is a moot point...

		Pat Rankin, rankin@eql.caltech.edu
Newsgroups: comp.lang.c
From: bjornw@colargol.edb.tih.no (Bjoern Wennberg)
Subject: Variable argument list question
Organization: Colargol, Trondheim College of Engineering
X-Newsreader: TIN [version 1.1 PL8]
Date: Tue, 15 Dec 92 18:29:06 GMT

Hi!

I am trying to make a function that 
	1. Has an variable argument list
	2. Manipulates the arguments that the argument list points to


Here is an example which illustrates the problem:

int main(void)
{
  char *flag;
  func(flag);
  /* flag == "test" */
}

void func(...)
{
  va_list args;
  va_start(args, "%s");
  
  va_arg(args, char *);
  
  /* allocate space for 'flag' by using 'args' */
  /* manipulate 'flag' by using 'args' */
  
  /* *args = new char[10];  doesn't work*/
  /* args = new char[10];  doesn't work*/
  /* memcpy() / strcpy() and friends doesn't work */

  /* 
   * debugger show me that 'args' points to the same address as 'flag'
   * does. But I cannot insert anything inside this address.
   */
  va_end(args);
}

Any comments are welcome.

bjornw>
--
bjornw@edb.tih.no     Bjoern Wennberg     Trondheim College of Engeneering

From: curry@hplred.HPL.HP.COM (Bo Curry)
Date: Tue, 15 Dec 1992 18:10:59 GMT
Subject: Re: Pointer to Function Question
Organization: Hewlett-Packard Laboratories, Palo Alto, CA
Newsgroups: comp.lang.c

Thanks to those who responded by email.
The answer (of course?!) is:

declare 

struct _WINDOW;
outside, and prior to, the first prototype referencing it,
so it will have file scope instead of local scope.

Thanks again,
Bo Curry

Newsgroups: comp.lang.c
From: manus@evolving.com (Manus Hand)
Subject: Re: Another C palindrome puzzle
Date: Thu, 17 Dec 1992 22:34:14 GMT
Organization: Evolving Systems, Inc.
X-Newsreader: Tin 1.1 PL4

fjh@munta.cs.mu.OZ.AU  (Fergus James Henderson) writes:
>
>   Next challenge: Write a palindromic "hello world" program in C without
>   using comments, #if, or #ifdef.  I think it should be possible.

Challenge accepted!  As Henderson did, I assert that new-line characters are
not significant when determining palindromism (palindromicity?).  So here's
a program that fits the bill, as short as I can make it.  Enjoy.

                        main(){
                        #define amgarp
                        #pragma}
                        puts("Hello world");amgarp
                        #pragma;)"dlrow olleH"(stup
                        }amgarp
                        #pragma enifed#{)(niam

It is trivial to make the program #include <stdio.h> and prototype its main()
function (for purists like me).

The program may not be strict ANSI (I don't know what constraints are placed on
#pragma directive syntax by the standard), so here is a much earlier version
of my solution, before being shortened again and again.  This should keep the
even the most nit-picky preprocessor happy as a clam:

                        #define enifed
                        #define fednu
                        #
                        main() fednu enifed
                        #
                        fednu fednu
                        #
                        { fednu enifed
                        #
                        fednu fednu
                        #define define }
                        puts("Hello world"); fednu enifed
                        #define undef ;)"dlrow olleH"(stup
                        } enifed enifed
                        #undef undef
                        #define undef {
                        #undef undef
                        #define undef )(niam
                        #undef enifed
                        #define enifed#

I also came up with a "mirror" palindrome solution (in which the characters
"(", "[", and "{" are reflected in the palindrome by ")", "]", and "}").  This
is given below:

                    #define enifed
                    main()enifed enifed
                    #
                    {;
                    #define stup;
                    puts(("dlrow olleH","Hello world"))stup
                    ;puts enifed
                    #
                    ;}
                    #define define()niamdefine enifed#

Now I suppose I have to come up with the NEXT challenge.  Okaaaayyyy....
how about a palindromic "Hello world" program, with no comments, #if's,
#ifdef's, <<<OR #define's!>>>

Keep me posted!

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Name:           Manus J. Hand (The Lobsterman)     >\          Phone:   busy
Quest:          Evolving Systems, Inc.             =:(((<      Home:    here
Favorite color: lavendar                           >/          E-mail:  yes
Newsgroups: comp.lang.c
From: jvigneau@cs.ulowell.edu (|Joe Vigneau|)
Subject: That scanf() thing.
Organization: Not Much
Distribution: comp
Date: Fri, 11 Dec 1992 17:09:53 GMT

Thanks * 10^6 to all those who helped me. Sorry, I couldn't reply to all
of you personally, as I recieved about 30 suggestions.  Again, thanks a lot.
--
jvigneau@cs.ulowell.edu-<All opinions are mine, not UMassLowell's>-Joe Vigneau
From: sweeney@husc3.harvard.edu
Newsgroups: comp.lang.c
Subject: Think C: Grafptr for stdout?
Date: 11 Dec 92 19:02:46 GMT
Article-I.D.: husc3.1992Dec11.140246.18399
Organization: Harvard University Science Center


Does anyone know how to access the Grafptr associated
with stdout?

On the Mac, using Think C, I am defining functions
that allow standard ANSI graphic programs to work.
These programs work on oher ANSI C systems;
we need to them to be interchanged with the Mac.

The console functions alone won't do the whole job.
I need a better mechanism for printing inverse video.

Ideas, suggestions and pointers welcome.

-Latanya 
 sweeney@husc3.harvard.edu
Newsgroups: comp.lang.c
From: yamada@stego.ifa.hawaii.edu (Hubert Yamada)
Subject: Re: Updated and improved "testing competence" questions
Organization: University of Hawaii, Institute for Astronomy
Date: Sun, 13 Dec 1992 08:37:31 GMT

In article <1gbstkINNfcp@almaak.usc.edu> ajayshah@almaak.usc.edu (Ajay Shah) writes:
>7. There is a C program which contains the line
>
>#include "min.h"
>
>   Now min.h EITHER contains
>        #define min(a, b) (a)<(b)?(a):(b)
>   OR
>        int min(int a, int b);
>   but you don't know which.
>
>   Write a test program which will tell you what is in min.h
>   You are not allowed to know anything about how your program is linked;
>   you are only allowed to write this program, and see it's behaviour in
>   compilation and execution.

I really wonder what this question is trying to test.  If you're trying
to see if your applicant knows about the danger of side effects when
macro has arguments, then why not just ask the more straight forward
question:

	Given:
		#define MIN(a,b) ((a) < (b) ? (a) : (b))
		int min(int a, int b) { return MIN(a, b); }

	What are the differences between using MIN() and using min()?  Is
	there any time when you could use one, but not the other?

I think that a valid answer to _your_ question would be: who cares
whether it's the macro or the function?  If I was that unsure about a
function that I had to use, I would either reimplement it, find a
suitable replacement, find the documentation, or write code that would
work correctly in either case.
-- 
Hubert Yamada                   * Our hero is called before the alien
yamada@galileo.ifa.hawaii.edu   * potentate!  Where it becomes clear that
yamada@uhunix.uhcc.hawaii.edu   * Spiff is about to be sacrificed to appease
Bitnet: yamada@uhunix.bitnet    * the evil god they call "Nollij"!
Newsgroups: comp.lang.c
From: bandy@netnews.jhuapl.edu (Mike Bandy)
Subject: Re: pointer assignment problem
Organization: JHU/Applied Physics Laboratory
Distribution: usa
Date: Mon, 14 Dec 1992 18:05:48 GMT

saud@seas.gwu.edu (Temporary account (slc 11/19/92)) writes:

>Hi:

>I am having problem with pointer assignment 

>look at this pleae
>	
>	function_node	*tmp_node;

>	tmp_node = (function_node *) malloc (sizeof(tmp_node));

Think about what tmp_node is; it's a pointer to a structure.  What gets
malloc'ed is (probably) 4 bytes of memory.  Stick a '*' in the sizeof
to tell it to allocate how much tmp_node _points to_ .  Like:

	tmp_node = (function_node *) malloc (sizeof(*tmp_node));

All the other problems you describe are due to running off past the
end of the alloced space into illegal space.

-- 

	Mike Bandy
	bandy@aplcomm.jhuapl.edu
	Johns Hopkins University / Applied Physics Lab
Newsgroups: comp.lang.c,comp.lang.pascal,comp.lang.c++
From: jhaide@novell.com (Janos A. Haide)
Subject: Re: Date -> Day of week conversion
Organization: Novell, Inc. --Austin
Date: Fri, 11 Dec 1992 20:03:10 GMT

In article <Bz3I8K.LDJ@ccu.umanitoba.ca> ummalik@ccu.umanitoba.ca (Ijaz Rashid Malik) writes:
>
>Could someone please forward me algorithm to convert the date (in dd.mm.yy
>or yy.mm.dd format, but assume individual fields can be obtained as integers)
>to corresponding day of the week.
>
>Thanks very much.
>
>Malik

Since you have crossposted in comp.lang.c I'd say that you can simply
initialize a few fields on a struct tm and then apply mktime() on it.
One of the fields will be set to the week of day. 

As far as a generic formula goes, here is one I've seen a few days ago 
(PASCAL-ish):

N:=(Trunc(M*2.6-0.1)+D+Y+Y div 4+5*C+C div 4) mod 7

Where:
D = day of month
Y = year of the century.
C = century.
M = Month - 2.
    ( January M=11 , February M=12 )

Result is an 0-6 integer.
 
Later,
Janos
jhaide@novell.com
From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
Newsgroups: comp.lang.c
Subject: Re: alias acess
Date: 20 Dec 92 23:32:08 GMT
Organization: McGill Research Centre for Intelligent Machines

In article <980@rc1.vub.ac.be>, jcu@dec5.ulb.ac.be (Jean-Christophe Ury) writes:

> I use ULTRIX V4.3.
> I 've  some aliases defined in my shell.I would access these aliases
> via a C program. Is it possible.

Short answer: no.

Long answer: not without a nearly incredible amount of really really
ugly, system- and shell-specific, kludgy, brittle code, and probably
root priviliges as well.  You would be much better off finding another
way to solve whatever problem you're trying to solve.

> email : jcu@134.184.80.3

That's not really a valid mail address.  The usual syntax for mail
using numeric addresses would read jcu@[134.184.80.3] instead, and even
that is usable only from Internet-connected machines, or the (rare?)
other machine that actually does something sensible with numeric
addresses.

					der Mouse

			    mouse@larry.mcrcim.mcgill.edu
Newsgroups: comp.lang.c
Subject: re: find the number difference of dates
From: lembark@sysjj.mdcbbs.com
Date: 11 Dec 92 10:37:10 GMT
Organization: EDS Unigraphics, Cypress CA
Nntp-Posting-User: eschner

easiest way to find the difference between two days:

regardless of leapyears, days in the month, etc: there are always 24 hours in 
a day and 3600 sec in a day.  another nice trick is that the absolute
difference of two numbers in a modular base == (a - b + base ) % base (e.g., 
( time of day differences: ( hour1 - hour2 + 24 ) % 24 )).

	time_t time1, time2;
	time_t n = 3600 * 24, days1 = time1/n, days2 = time2/n;
	time_t max = (time_t)-1/n, diff = (days1 - days2 + maxday) % max;

(time_t)-1 works since time_t is normally an unsigned quantity; (time_t)~0 does
the same basic thing (32 bits of 0xFFF... will do the same thing).

another approach is to convert both of them to unsigned int's by calculating
the number of days since a particluar date earlier than both (e.g., 1/1/1900)
and take the difference of the result:

{ 	/* somewhere in your code: */
	unsigned days1 = nndate( year1, month1, day1 ),
		 days2 = nndate( year2, month2, day2 ),
		 difference = days1 < days2 ? days2 - days1 : days1 - days2;
}


/*
   convert a year, month and day value to number of days since 1/1/BASE_YEAR,
   obvious choices for BASE_YEAR are 1900 [which wasn't a leap year] or 
   1970.  this will only work with julain dates (most of us don't have much
   to do with gregorian dates, however, so that't o.k.).

   BASE_YEAR == 1970 => unsigned days has the same time span as
   unsigned long seconds: about 180 years...
*/
unsigned nndate( unsigned yy, unsigned mm, unsigned dd )
{
	unsigned nn, i, j;
	unsigned month_days[13][2] =
		{ {0,31,28,31,30,31,30,31,31,30,31,30,31},
		  {0,31,29,31,30,31,30,31,31,30,31,30,31} };

	for( i = BASE_YEAR, nn=0 ; i < yy ; i++ )
		nn+= 365 + leapyr(i);

	i = leapyr( i );	/* save repeated calls to leapyr */
	for( j = 0 ; i < mm ; i++ )
		nn+= month_days[j][i];

	nn+= dd;

	return nn;
}

int leapyr( year )
{
	return ( (!(year%4)&&(year%100) || !(year%400) );
}

Newsgroups: comp.lang.c
From: pjones@asl.slb.com
Subject: Passing Variable Arguments -twice-
Reply-To: pjones@asl.slb.com
Organization: Schlumberger/Anadrill Sugar Land, TX
Date: Fri, 11 Dec 92 18:58:32 GMT

I'm trying to pass some arguments to printf() through another routine,
and I can't get it to work.  Here's what I'm doing:

void disp_error(char *msg, ...)
{
  /* Screen manipulation stuff */
  .
  .
  .

  /* Print the error message */
  cprintf(msg, ...);    <== I want to pass the arguments that disp_error()
                            received directly to the printf() routine without
                            manipulating them.  This compiles but does not
                            work.
}

void main(void)
{
  disp_error("This is the letter 'C': %c", 'C');
}

Now I know I could use sprintf() in main() and pass the formatted string
to disp_error(),  but this routine is going to be called from a lot of places
and I am trying to avoid that trouble.  I'm sure this is possible to do,  I
just need someone to tell me how.  Thanks in advance.

Phil Jones
pjones@asl.sinet.slb.com
Newsgroups: comp.lang.c
From: fischer@iesd.auc.dk (Lars Peter Fischer)
Subject: Re: Question to test general C knowledge
Organization: Mathematics and Computer Science, Aalborg University
	<1992Dec10.225159.14437@sfu.ca>
Date: 17 Dec 92 05:04:42


>>>>> "Darcy" == Darcy Smith (darcys@fraser.sfu.ca)

Darcy> would you prefer someone who could give you a practical answer
Darcy> like "3 if that is how the compiler implements it" or well on
Darcy> page such-and-such in the BOOK that is my life it says...?

Well, in my book "confusing compiler with language" does not mean
"practical". So, I'd much prefer someone who understands the language.

/Lars
--
Lars Fischer, fischer@iesd.auc.dk | It takes an uncommon mind to think of
CS Dept., Aalborg Univ., DENMARK. | these things.  -- Calvin
From: jcu@dec5.ulb.ac.be (Jean-Christophe Ury)
Newsgroups: comp.lang.c
Subject: alias acess
Date: 17 Dec 92 15:19:07 GMT
Distribution: world
Organization: Free University Brussels  - Belgium -  Department of Molecular Biology



It may seems stupid but I ask you anyway,

I use ULTRIX V4.3.
I 've  some aliases defined in my shell.I would access these aliases via
a C program. Is it possible.

Please answer me.


email : jcu@134.184.80.3
Newsgroups: comp.lang.c
From: mccall@mksol.dseg.ti.com (fred j mccall 575-3539)
Subject: Re: Question to test general C knowledge
Organization: Texas Instruments Inc
Date: Tue, 15 Dec 1992 17:03:25 GMT

In <4232@litchi.bbn.com> cbarber@bbn.com (Chris Barber) writes:

>In article <scott.40.724096473@kronos.com> scott@kronos.com (Scott Riegelhaupt-Herzig) writes:
>>Or, one of my favorites:
>>Name the four NULLs in C.
>>
>>(They are, of course, NULL character, NULL pointer, NULL string, and null 
>>statement.)

>IMHO, this is exactly the kind of question one should *not* ask. What
>particular benefit would a programmer gain from being able to enumerate
>this list of replies?  

I agree.  However, I think probably THE most useful question to ask
might be something like, "Discuss the difference between zero and a nil
pointer in C.  Why does this issue create so much confusion, and what
is the correct interpretation of 'if (varname)' if varname is a
pointer to character, integer, array from 0 to 20 of character.

Face it, you aren't going to find out if they know anything unless
they have to write an essay.  And it's better to do that stuff orally
anyway, during the interview, so as far as I'm concerned this whole
'test their competetence' philosophy is a lose.  People who don't
'test' well will do poorly, even if they know what they're doing.  An
interviewer can make allowances for things like that by prompting them
if necessary (and any decent interviewer should be able to tell if the
problem is nerves or a lack of knowledge).


	
-- 
"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: reagle@umbc8.umbc.edu (Mr. Joseph Reagle; MEYERHOFF (U))
Subject: Examples of Documentation
Organization: University of Maryland, Baltimore County Campus
Date: Fri, 11 Dec 1992 21:10:30 GMT

	I am interested in any sites, or personal examples you might
send me that you think demonstrate good programming style.
	Simply, I think mine is ugly, I don't even have a _style_,
it's generally whatever I feel like doing at the moment.
	I'm not really interested in a debate about what is good and
bad, I know different people have different opinions.  I am in pursuit
of defining my own definition of what good and bad are, and I would
appreciate a sampling of what other people think to be 'good'
documentation.
					Joe

Newsgroups: comp.lang.c
From: fred@trot.ibp.fr (Frederic PETROT)
Subject: Re: Question to test general C knowledge
Organization: Laboratoire MASI, Paris, France
Date: Fri, 18 Dec 1992 09:37:17 GMT

d_north@ondec.lonestar.org (David G. North, CCP) writes:
>Or better yet, what is the type and value of the following expression:
>  "this is a test"[4]

try this one (due to a friend of mine):

main()
{
   printf("%c", unix["abc"]);
}

on a unix system, for sure! (no include file needed)

Fred.
From: bob@comlab.gatech.edu (Bob Baggerman)
Newsgroups: comp.lang.c
Subject: Re: ISAM routines
Date: 16 Dec 92 22:17:06 GMT
Organization: GTRI Communications Lab

M.Jackson@unsw.edu.au writes:
>Does anyone know of any routines to implement ISAM under C ? We are 
>working on a project which needs indexed sequential access and (as 
>always) don't want to reinvent the proverbial wheel.

Lots of people sell these.  The one I like best is BTree/ISAM by Softfocus.
It is only US$79 for the single user package and US$115 for the multiuser
package from Programmer's Connection (800-336-1166 in the US).  I like it 
because it is inexpensive and compiles on every Unix and DOS system I've 
tried, with both ANSI and K&R C compilers.  I use the same database package
on all the systems I develop for.  Neat!

Bob
-- 
Bob Baggerman                         !  bob.baggerman@gtri.gatech.edu
Communications Laboratory             !  bob@comlab.gatech.edu
Georgia Tech Research Institute       !  qseclrb@prism.gatech.edu
Atlanta, GA  30332  USA               !  404-894-3525
Newsgroups: comp.lang.c
From: mox@vpnet.chi.il.us (William Moxley)
Subject: Best fit exponential curves
Organization: Vpnet Public Access
Date: Mon, 14 Dec 1992 07:57:43 GMT

Does anyone have any code or information about calculating best fit
exponential curves?

		William Moxley
		mox@vpnet.chi.il.us