HDTenEightyP/NetNews huggingface dataset:
From: niko@iastate.edu (Nikolaus E Schuessler)
Subject: Re: C if else statements HELP
Organization: Iowa State University, Ames, IA
Date: Fri, 8 Jan 1993 17:40:46 GMT

In article <1993Jan8.160740.22055@magnus.acs.ohio-state.edu> ctoth@magnus.acs.ohio-state.edu (Christopher M Toth) writes:
>	Hi! I just started learning C and have run into problems with
>'if' and'else' statements. I have a program that I am *trying* to write. The
>basic format is:
>
>	printf ("which do you choose?");
>	scanf("%d", &n);
>	choice#1
>	choice#2
>	choice#3
>	choice#4
>
>	if choice #1
>		printf.....
>	if choice #2
>		printf.....
>	if choice #3
>		printf.....
>	if choice #4
>		printf.....
>

how about:

    switch (n) {

       case 1:
          break;
       case 2:
          break;
       case 3:
          break;
       case 4:
          break;

       default:
          break;
    }

This will only work on certain types though (ints, chars ...)

If you don't already have it, you should get the Kernigan and Richie
C book.


-- 
Niko Schuessler               
Project Vincent Systems Manager              email: niko@iastate.edu
Iowa State University Computation Center     voice: (515) 294-1672
Ames IA 50011                                snail: 272 Durham
From: sgr@alden.UUCP (Stan Ryckman)
Newsgroups: comp.lang.c
Subject: Re: date format
Date: 4 Jan 93 18:10:40 GMT
Organization: Alden Electronics, Westboro, MA

In article <92364.133407EPA100@psuvm.psu.edu> EPA100@psuvm.psu.edu writes:
>what I am attempting is as follows
>
>struct dat{
>  int dayr;     /* struct to get the date from the system through dos.h*/
> char damo;
> char dada;
> } da
>
>getdate(&da);
>printf("%i\n", da.dayr);
>printf("%s\n", da.damo);
>etc...
>I am able to get the year 1992, but when I attempt to print the month and day I
>get the Borland copyright info printing on the screen.

Your printf is at least part of the problem.  You are using "%s" with
a character.  Use 
    printf("%d\n", da.dayr);
    printf("%d\n", (int) da.damo);

(Here I'm presuming that they store a 1-byte binary integer value in the
character.)

Stan.
--
X-Obligatory-.sig
    Stan Ryckman   sgr@alden.UUCP
Newsgroups: comp.lang.c
From: misar@rbg.informatik.th-darmstadt.de (Walter Misar)
Subject: Re: Exact-sized types (was Re: Typedefing builtin... thanks.)
Date: Wed, 6 Jan 1993 19:22:21 GMT
Organization: TH Darmstadt

In article <F9I0BER@math.fu-berlin.de>, rene@hamel.uucp (Rene Mueller) writes:
> In article <84931@ut-emx.uucp>, jamshid@ut-emx.uucp (Jamshid Afshar) writes: 
> |> I don't understand the purpose of the "at-least-N-bits" types.  C
> |> already has those -- char (>=8), short (>=16), int (>=16), and long
> |> (>=32).  What does your extra level of indirection buy you?
> You are'nt correct:
> int is as long as a single machine word on the machine (on some machines this
> means 12bit), on this machines also a short is 12bit long and a long is 24bits
> long...
> The same is with characters
> Some compilers will give you only the original ASCII-Characterset and a 
> char-value with this machines is 7bit long, all other bits stored in memory
> for this value will be ignored...

Nope, he is correct. I don't know exactly about chars, but ints and shorts
have to have at least 16 bit (on a binary machine this is, the definition
was, that both must be able to hold all numbers n with -32768<n< +32768).
Similar with longs: they have to be at least 32 bits. Int should have a
size of a 'natural word' on a given machine, but if this proves to be to small,
an int has to be constructed out of several words.

-- 
Walter Misar                                | It is impossible to enjoy
misar@rbg.informatik.th-darmstadt.de        | idling thoroughly unless
                                            | one has plenty of work to do.
From: jar@solva.ifi.uio.no (Jo Are Rosland)
Newsgroups: comp.lang.c
Subject: Re: Problem with string processing.
Date: 4 Jan 93 19:17:47 GMT
	<1993Jan4.025351.26173@osuunx.ucc.okstate.edu>
Organization: Dept. of Informatics, University of Oslo, Norway
X-Md4-Signature: fddf08a7e36cc2a09f8fb09a6d766c35
Originator: jar@solva.ifi.uio.no

In article <1993Jan4.025351.26173@osuunx.ucc.okstate.edu> Gordon Couger writes:
>   #include <strings.h>
You don't need this, you don't use any string functions.

>   char *add_char(char *s, char c)
You ought to use "int" as the type of "c".

>      {
>      char *sp = s;
>      while(*sp++)
>	 ;  /* finds end of string and leave pointer for adding char */
>      *sp-1 = c; 
This parse as "(*sp)-1 = c", where "(*sp)-1" isn't an lvalue.  You
probably meant "*(sp - 1) = c".

>      *sp = NULL;
Don't use NULL, use '\0' or 0.  NULL is a null pointer, not a character.

>      return s;
I know this is the way the standard functions do it, but I've always
wondered why.  The end of the string is a more interesting value most
of the time, as you can use that to add more to the end of the string
without having to scan it from the beginning each time.  If the
functions strcpy() and strcat() did return the end of the string,
they'd be a lot more efficient when building strings from many
concatenations.

>      }

>   Gordon Couger
>   AB5Dg   Agriculture Engineering Oklahoma State University
>   gcouger@olesun.agen.okstate.edu 405-744-6514 day 744-2794 evenings   

Try this one instead:

    char *add_char(char *s, int c)
    {
        char *sp = s;
        while (*sp++)
            ;
        *(sp - 1) = c;
        *sp = '\0';
        return s;
    }

...or this one, if you'd like to return the end of the string:

    char *add_char(char *s, int c)
    {
        while (*s++)
            ;
        *(s - 1) = c;
        *s = '\0';
        return s;
    }

Hopefully my versions are also full of mistakes, so we can keep this
thing going :-)
--
Jo Are Rosland
jar@ifi.uio.no
Newsgroups: comp.lang.c
From: sj@cs.brown.edu (Shuang Ji)
Subject: Re: Missing sound function
Organization: Brown Computer Science Dept.
Date: Mon, 11 Jan 1993 19:02:22 GMT

In article <0096672C.05F89EC0@128.104.39.173>, sprott@128.104.39.173 (Sprott@Juno.Physics.Wisc.Edu) writes:
|> I'm inexperienced in C but just converted a BASIC program to Microsoft Quick
|> C v. 2.5.  Everything works fine, except there does not appear to be a C
|> equivalent to the BASIC statement SOUND frequency, duration for generating
|> audible tones.  Does anyone know a way to accomplish this?  I also have
|> Turbo C++ for DOS v. 3.0, but it also lacks sound capability.  Thanks.

Turbo C++ does have sound capability. In my impression, there is a function
called sound() which will enable you to send frequency to the audio port.
There is also a function whose name I forgot that can stop the speaker.
Check your on-line manual for details.

Hope this helps.



Shuang
Newsgroups: comp.lang.c
From: Seokmin Ahn <smahn@vx.cis.umn.edu>
Subject: HELP : C programming Guideline
X-Xxmessage-Id: <A77712D18C01C378@me51-3-120.me.umn.edu>
X-Xxdate: Mon, 11 Jan 93 12:04:33 GMT
Organization: University of Minnesota
X-Useragent: Nuntius v1.1.1d17
Date: Mon, 11 Jan 1993 18:00:51 GMT

Hi netters,

I am looking for a C  (not C++) programming guideline.

Thank you.
From: vyskocil@taloa.unice.fr (Vyskocyl)
Newsgroups: comp.lang.c
Subject: How to read without echo.
Date: 4 Jan 1993 17:44:53 +0100
Organization: University of Nice Sophia-Antipolis, France
NNTP-Posting-Host: taloa.unice.fr

Hi!
I got a little question, which will certainly be just a 
piece of cake for such talentuous programmers as you are.

I only want to read a word on the keyboard without any
print on the screen. I mean, I want someone to answer
a question on his keyboard without any echo of what he
is typing. It will end just after he pressed 'return'.
ex: do a little program which does perform this :
 
 What's the color of a pumpkin ?:
(now the guy type something but it doesn't appear on
his screen!)
 then :
 True! or False! whether the answer is light-blue or
not 8-) .

Could you guy do that ? 
I'm sure you can so I'll offer my true sympathy to
the first of yours who will be able to answer this 
little frenchie question!!!

-Mike-
From: bhoughto@sedona.intel.com (Blair P. Houghton)
Newsgroups: comp.lang.c
Subject: Re: How can you evaluate an arbitrary function?
Date: 7 Jan 1993 03:00:30 GMT
Organization: Intel Corp., Chandler, Arizona
NNTP-Posting-Host: stealth.intel.com

In article <1993Jan6.202453.8630@news.tufts.edu> slahiri@jade.tufts.edu (Sandip Lahiri) writes:
>Suppose you have to write a program which would accept any arbitrary 
>function f(x) and calculate its values for x = ... . The program has 

I dunno.

How'd they do it when they wrote bc(1)?

				--Blair
				  "Before whom?"
Newsgroups: comp.lang.c
From: mikes@Ingres.COM (Mike Schilling)
Subject: Re: NH-- > NH
Date: 10 Jan 93 18:06:14 GMT

From article <28290@dog.ee.lbl.gov>, by torek@horse.ee.lbl.gov (Chris Torek):
> In article <1993Jan9.010946.3172@draco.macsch.com>
> dnl@convex.is.macsch.com (David Lombard) writes:
>>Never confuse "Gee it works" with "that's the result you should expect."
> 
> Indeed.  `Gee, using this nitroglycerin to start the barbecue works
> really well!'  Maybe so, but it is *not* recommended.
But it was the best nitroglycerin!  (Apologies to Lewis Caroll.)
----------------------------------------------------------------------------
mikes@ingres.com = Mike Schilling, INGRES, An ASK Group Company, Alameda, CA
Just machines that make big decisions,
Programmed by fellows with compassion and vision.	-- Donald Fagen, "IGY"
From: mcglk@cpac.washington.edu (Ken McGlothlen)
Newsgroups: comp.lang.c
Subject: Re: Fopening a text file
Date: 5 Jan 93 08:51:03 GMT
Article-I.D.: yang.MCGLK.93Jan5005103
Distribution: usa
Organization: Dubious.
NNTP-Posting-Host: yang.cpac.washington.edu

William Moxley (mox@vpnet.chi.il.us) writes:
+----------
| When I try do a fopen("filename", "rt"); it opens the file as a binary.  If I
| drop the t, is still creates a binary file.  So how do I make fopen create a
| straight text file?  [...]  I normally don't write programs for machines
| other than dos.
+----------

I hate to tell you this, but the ugly truth is:

	Unix only has one kind of file.  The binary file.

MS-DOS, designed with all the force of Microsoft's wisdom, chose to represent
the end-of-line character with two characters:  ^M (ASCII 13, or CR, or \r in C
parlance) followed by ^J (ASCII 10, or LF, or \n in C parlance).  However, Unix
systems only use LF to determine end-of-line.  So in DOS, when you do

	fprintf( textfile, "%s\n", "This is a line." );

on a file opened with the "wt" mode of fopen(), you get, in ASCII,

	This is a line.\r\n

Unix, however, only gives you

	This is a line.\n

DOS will give you the same if you open the file with just "w" as the mode; just
the LF instead of the CR-LF pair.

MS-DOS chose to make things a bit more complicated, and normally, this wouldn't
be a big problem, except that you're trying to get a file to run under Unix
which produces files you want to move to the DOS system.  And so your life
becomes messy.  However, there are a couple of easy scripts you can use, which
I've appended to this message, which will convert back and forth between Unix
text files and DOS text files.  Good luck.

							---Ken

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	unix2dos
#	dos2unix
# This archive created: Tue Jan  5 00:50:17 1993
# By:	Ken McGlothlen
export PATH; PATH=/bin:/usr/bin:$PATH
echo shar: "extracting 'unix2dos'" '(131 characters)'
if test -f 'unix2dos'
then
    mv unix2dos unix2dos~; echo shar: "moved unix2dos to unix2dos~"
fi; if test -d . ; then
sed 's/^X//' << \OogaBooga > 'unix2dos'
X#!/bin/sh
X#
X#	Converts Unix text files to something more friendly to DOS, by adding
X#	CRs to the ends of each line.
X
Xsed 's/$/
X
OogaBooga
if test 131 -ne "`wc -c < 'unix2dos'`"
then
	echo shar: "error transmitting 'unix2dos'" '(should have been 131 characters)'
fi
chmod 700 'unix2dos'
fi
echo shar: "extracting 'dos2unix'" '(129 characters)'
if test -f 'dos2unix'
then
    mv dos2unix dos2unix~; echo shar: "moved dos2unix to dos2unix~"
fi; if test -d . ; then
sed 's/^X//' << \OogaBooga > 'dos2unix'
X#!/bin/sh
X#
X#	Converts a DOS text file to something more Unixy, by stripping the
X#	CRs off the ends of the lines.
X
Xsed 's/
X
OogaBooga
if test 129 -ne "`wc -c < 'dos2unix'`"
then
	echo shar: "error transmitting 'dos2unix'" '(should have been 129 characters)'
fi
chmod 700 'dos2unix'
fi
exit 0
#	End of shell archive
Newsgroups: comp.lang.c,rec.humor
From: hollasch@kpc.com (Steve Hollasch)
Subject: Re: Program to convert .EXE to a "C" source file?  I really need one!!
Keywords: tanner joystick ms-dos mouse keyboard carburettor platypus
Organization: Kubota Pacific Computer, Inc.
Distribution: usa
Date: Wed, 6 Jan 1993 17:18:52 GMT

| What's the name of this news group?

    Hmmmm, lemme check your newsgroups line ...

> Newsgroups: comp.lang.c,rec.humor

    Well, THAT should clear things up!

______________________________________________________________________________
Steve Hollasch                                   Kubota Pacific Computer, Inc.
hollasch@kpc.com                                 Santa Clara, California
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.lang.c
Subject: Re: struct vs. typedef
Date: 13 Jan 93 03:59:20 GMT
Reply-To: dave@cs.arizona.edu (Dave Schaumann)
Organization: University of Arizona

In article <1993Jan13.020738.9171@massey.ac.nz>, news@massey (USENET News System) writes:
>I prefer,
>
>#define ITEM struct n
>
>typedef ITEM {
[...]
>};

Echh!  IMHO, this is bletcherous.  The biggest abuse of the preprocessor
I can think of is to use it to hide keywords; to make the language look
like something it's not.

Why not just do it like this:

typedef struct foo *foo_ptr ;

struct foo {
  /* whatever */
  foo_ptr succ, pred ;
  } ;

-- 
You unlock this door with the key of imagination.  Beyond it is another
dimension: a dimension of sound, a dimension of sight, a dimension of mind.
You're moving into a land of both shadow and substance, of things and ideas.
You've just crossed over into... the Twilight Zone.
Newsgroups: comp.lang.c
From: wrd@wdraper.uark.edu (William R. Draper)
Subject: Re: struct vs. typedef
Organization: University of Arkansas
Date: Mon, 11 Jan 1993 16:28:44 GMT

jar@solva.ifi.uio.no (Jo Are Rosland) writes:

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

If you would rather, you can try:

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

I usually define it as Silvernail has, but where you have several
instances of a pointer, it may be easier to define the pointer first.

Bill

email: wrd@engr.uark.edu
From: alane@wozzle.linet.org (J. Alan Eldridge)
Newsgroups: comp.lang.c
Subject: Re: Problem with string processing.
Date: 4 Jan 93 03:42:04 GMT
Organization: Disorganization

oleary@staff.tc.umn.edu writes:

> A much better version is:
>  
> void add_char_to_str(char ch, char *str)
> {
>         char tmp[2] = {0};
>  
>         *tmp = ch;
>         strcat(str, tmp);
> }
>  

Oh, dear.

tmp[0] has a 0 in it but tmp[1] is undefined. You are not creating
a nul-terminated string here.

If you'd said tmp[2]={0,0}; then all would be well on that front.

I guess it's implied that str has enough room to hold the extra character.

alane@wozzle.linet.org (J. Alan Eldridge)
Fido: The University of Walamaloo 1:272/38.473
Newsgroups: comp.lang.c
From: andrew@astro.psu.edu (Andrew Wilcox)
Subject: can a pointer cast to a void* be compared to (void*)0 ?
Organization: Department of Astronomy and Astrophysics, Penn State University
Distribution: comp
Date: Mon, 11 Jan 1993 00:46:45 GMT

This may be a FAQ, but I didn't see it in Steve Summit's excellent
list, so:

Can a pointer which has been cast to a void* be directly compared with
a (void*)0 in ANSI C, or does the void* have to be cast back to the
original type before the comparision?  I.e.,

     char* c = 0;
     void* p = (void*) c;
     if (p == 0)
       printf( "yes\n" );

Is this program guaranteed to print "yes"?

I am writing a dynamic typing system for C, so this question is not
just of idle curiousity.

Thanks all,

Andrew Wilcox
Department of Astronomy & Astrophysics, Pennsylvania State University
(awilcox@astro.psu.edu)
Newsgroups: comp.lang.c
From: jacobs@erc.cat.syr.edu (David Quinn-Jacobs)
Subject: Code Analysis Tools Info Request
Date: Mon, 4 Jan 93 16:45:14 EST

I am looking for code analyis tools (other than cflow and cxref) which
perform the following functions:

    o    Cyclomatic Complexity Analysis (McCabe)
    o    Calling Trees (graphic or textual)
    o    Cross Referencing (particularly noting global variable usage)

It does not matter if the tools are commercial or in the public domain.  (If 
they apply to Fortran as well as C, that is a plus.)

Please post replies to the following email address since I cannot access
news very often.  Thanks in advance.
----------------------------------------------------------------------------
Dave Quinn-Jacobs                           Phone: (315) 724-1100
The Analytical Sciences Corp. (TASC)          FAX: (315) 724-3330
555 French Rd.                              Email: jacobs@erc.cat.syr.edu
New Hartford, NY 13413
-- 
------------------------------------------------------------------------------
   			       David Quinn-Jacobs

		  *          Plainfield Associates
From: bx314@cleveland.Freenet.Edu (Joseph J. Gebis)
Newsgroups: comp.lang.c
Subject: MS-DOS char set, num, caps, scroll lock
Date: 12 Jan 1993 02:16:16 GMT
Organization: Case Western Reserve University, Cleveland, OH (USA)
Reply-To: bx314@cleveland.Freenet.Edu (Joseph J. Gebis)
NNTP-Posting-Host: hela.ins.cwru.edu



	Hi.  I want to know how to access and change the dos character
set using C.  Any help would be appreciated.

	I would also like to know how to set the status of the num lock, 
caps lock, and scroll lock keys using C.  Thanks.


Newsgroups: local.unix.help,comp.lang.c,comp.os.vms
From: kaarts@ccu.umanitoba.ca (Kenneth John Aarts)
Subject: Re: Using C to read Fortran Files
Organization: University of Manitoba, Winnipeg, Canada
Date: Wed, 6 Jan 1993 23:31:24 GMT

In <C0G1rw.81L@ccu.umanitoba.ca> kaarts@ccu.umanitoba.ca (Kenneth John Aarts) writes:

>I have a fortran program that does essentially

>	open(unit=1,"test",status='new')
>	write(1,10) 'cArt'
>10	format(a4)
>	end

>and then a C program that reads it:

>	int d1,d2,d3,d4,d5;
>	FILE *fp;
>	fp=fopen("test","r");
>	fscanf(fp,"%c%c%c%c%c",&d1,&d2,&d3,&d4,&d5);
>	printf("%d %d %d %d %d\n",d1,d2,d3,d4,d5);

>The output of the C program is:

>  10  65  114  116   13

>  LF  A    r   t    CR

>However, a fortran program reading the test program does see cArt.

A little more information:

This is all done on VMS.  The fortran created file has a 'fortran carriage
control' record attribute.

I do not have the option of rewriting the fortran code to add carriage
control to the format statement.

I need a way to convince VMS not to interpret the file before sending it's
contents to the C program.

Thanks again,

Ken
From: steve@dbaccess.com (Steve Suttles)
Newsgroups: comp.lang.c
Subject: Re: Recurring date/times?
Date: 7 Jan 93 03:59:50 GMT
Organization: Cross Access Corp., Santa Clara, CA
X-Newsreader: Tin 1.1 PL4

rmah@panix.com (Robert Mah) writes:
: Anyone have any suggestions on good data structures for representing 
: recurring dates and times.  That is, things like "the first teusday
: of every month" or "three days before the end of every month", etc.
: 
: I'm looking for something flexible and compact that I can easily check
: to see if a given date/time falls on the recurring date/time.
: 
Rob,

You either need to redefine (restrict) the problem or implement the
solution.  As you stated it, you want an algorithm to manipulate dates.
You want the capability of adding (signed) deltas, starting with
today's or any numeric date, and advancing/retreating to a given day-of-the
week.  Many routines have been written to do date computations; your
data structure, if you need to retain all these capabilities, is forced
to be a codification of the calls necessary to do these manipulations.
You can probably get by with a paired list: What to do and what to do it
with, for as many steps as you want: 
	(code for) start_with_fixed_date, (value for) November 1
	(code for) advance_to_DOW, (code for) Tuesday
	(code for) advance_by_delta, (value for) -7
	(code for) stop_processing, (no parameter required)
would give you some warning for election day.  Then you need to interpret
this list and deal with the values.

The other thing you could codify is the checks to make:
	(code for) compare_DOW, (code for) Tuesday
	(code for) compare_day_of_month_less_than, (value for) 3
You can quit after an untrue condition, or after a true one, or whichever;
to be truly flexible, you'd basically have to implement an RPN notation
with operators for "get DOW" and "load DOW constant" and all the comparison
(and boolean) and arithmetic operators.

And of course, you could restrict the scope of the problem--that you only
check day-of-the-week and the range of day-of-the-month, for example.

What you are asking for is very specific and not likely to pre-exist...

sas
-- 
Steve Suttles                Internet:  steve@dbaccess.com      Dr. DCL is IN!
CROSS ACCESS Corporation     UUCP: {uunet,sgiblab}!troi!steve  Yo speako TECO!
2900 Gordon Ave, Suite 100   fax: (408) 735-0328              Talk data to me!
Santa Clara, CA 95051-0718   vox: (408) 735-7545   HA! It's under 4 lines NOW!
Xref: sparky comp.lang.c:19218 comp.lang.pascal:7852
Organization: Penn State University
Date: Mon, 4 Jan 1993 21:27:53 EST
From: Carl Fago <CDF1@psuvm.psu.edu>
Newsgroups: comp.lang.c,comp.lang.pascal
Subject: TPW 1.5 Controls and MDI Windows

Another TPW question...

Is there a method to put controls (Buttons and Icons) in the MDI client
window?

I tried putting a simple pushbutton using the New (PButton...) function
in the Init for the TMDIWindow but all I get is a button in its own
MDI child window.

Any ideas?

 *-=Carl=-*  INTERNET - cdf1@psuvm.psu.edu | In battle, you can do   |
             GEnie - C.FAGO1               | everything right...     |
 Carl Fago   State College, PA             | and _still_ lose!       |
From: johnl@informix.com (Jonathan Leffler)
Newsgroups: comp.lang.c
Subject: Re: struct / union / function declaration
Date: 12 Jan 93 19:06:50 GMT
Organization: Informix Software, Inc.

In article <1993Jan12.115527.136146@eratu.rz.uni-konstanz.de>
mueller@DG1.CHEMIE.UNI-KONSTANZ.DE (Christian M"uller) writes:
>I have a problem defining a union like this:
>  
>struct s {
>        union node *arg;
>        union node (*func)(union node);
>};
>
>union node {
>        struct s fun;
>        int n;
>};

>A similar problem is the following:
>
>struct x {
>	int (*func)(struct x);
>};

Before the struct s declaration, use the line:

union node;

That is a forward reference which defines the name "node" as a tag for a union.

The struct x problem is harder; it would work if you used:

struct x {
	int (*func)(struct x *);
};

The problem is, before you can pass a structure as a parameter (rather than
a pointer to the structure), you have to know all about it.  You won't know
all about it until you reach the closing brace.

And closer scrutiny of struct s reveals the same problem there: you are
trying to pass an incomplete type as a parameter to the function pointer
element, and you can't do it.  Use struture/union pointers instead -- they
are probably more efficient too.

My mind is boggled at the thought of trying to use struct x in real life.
Newsgroups: comp.lang.c