HDTenEightyP/NetNews huggingface dataset:
From: mcs@goblin.caltech.edu (Martin Shepherd)
Newsgroups: comp.lang.c
Subject: Re: Union-initialization portability
Date: 2 Oct 1992 18:55:03 GMT
Organization: California Institute of Technology, Pasadena
NNTP-Posting-Host: goblin.caltech.edu


In article <14836@goanna.cs.rmit.oz.au>, ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
>There are a lot of subtle points about unions.  The point you may not be
>aware of is that a C compiler is allowed to use different representations
>for pointers of different types.  There are two useful exceptions: void*
>and char* must have the same representation, and all struct * pointers
>have the same representation.

I was aware that pointers could have different *sizes*. What I was
vaguely hoping was that their was a standard implementation of 'void *',
and that that implementation would itself be a union of all possible
pointers, arranged such that different pointers would simply take up
different numbers of contiguous bits of the 'void *'.  For example
assuming that a 'void *' was represented by a 32-bit int and an 'int
*' by a 16-bit int the storage in this scheme might be arranged as:

          12345678123456781234567812345678
void *   |--------------------------------|
int *    |----------------|000000000000000|
float *  |----------------|000000000000000|
char *   |--------------------------------|
etc..
Where the zeroes represent unused parts of the 'void *'.

I now know that this is wrong. I have had some very helpful discussion
via email about alternative techniques. The one that I think that I
will settle on, still initializes the union as before but then, the
function that checks the descriptor before installing it in a symbol
table, will extract the 'void *' pointer, cast it to the pointer type
of the original initializing variable and finally assign it back to
the appropriate pointer in the union.

ie.
        void *tmp_ptr;
	for(i=0; i<NUM_VAR; i++) {
          switch (test[i].type) {
          case FLOAT_PTR:
            tmp_ptr = test[i].valof.init;
            test[i].valof.fptr = (float *) tmp_ptr;
            break;
          case INT_PTR:
            .
            .
            etc...
          };
        };

This complies with my unstated aims of retaining static initialization
and keeping down the number of subsequent casts in the program.

(The need for the tmp_ptr intermediary in the above example was
 suggested by Mark Brader - to quote "you can't read from a member and
 in the same assignment store into a member that *partially* overlaps
 it.  At least, that's the way I read the applicable section". I agree
 with this, so if you think that it is wrong please direct flames at
 me, not at Mark.)

Thanks to all those who responded.

Martin Shepherd   (mcs@phobos.caltech.edu)
From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.lang.c
Subject: Re: unpredictable post-decrement behavior.
Date: 29 Sep 92 23:05:56 GMT
Organization: negligable

In article <28638@vedge.UUCP> michel@vedge.UUCP (Michel Trudeau) writes:
>herzog@ux5.lbl.gov (Hanan M. Herzog) writes:
>: See this:
>: 	         product *= (double)(4 * n * n) / ((4 * n * n++) - 1);
>: 
>: Some compilers had no problem with this line at all. However some
>: hurled completely upon sight of the 'n++'. A few compilers required
>: me to place the 'n++' on the next line in the while loop. So
>: the code looked like:
>: 
>: 	         product *= (double)(4 * n * n) / ((4 * n * n) - 1);
>: 		 n++;
>: 
>: Why did some compilers get and others not?
>: 
>   In 'C', unpredictable means undefined behavior.
>

The behavior for n++ is NOT undefined or unpredictible.  The problem
is the some compilers are broken.  Either the expression parsing is
broken or (most likely) the optimization is getting a little over
enthusiastic.  Either way, the compiler is broken.  I worked on a
compiler that would not properly compile some (only relatively)
complex equation unless I declared a temp variable and broke it
into two lines.  This equation didn't even try using the autoincrement,
it was just a poor compiler!  Worse it wasn't the compiler that had
the problem w/ it but the calculation was incorrect at runtime (I
was VERY upset when I finally found the stupid problem....)

Try disabling optimizations on the compilers that didn't like it
and see if it works.


		-Richard Hartman
		hartman@uLogic.COM

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Extensive studies have shown that 93% of all statistics are meaningless.

Newsgroups: comp.lang.c
From: steve@taumet.com (Steve Clamage)
Subject: Re: line number in C program
Organization: TauMetric Corporation
Date: Tue, 6 Oct 1992 15:29:49 GMT

hm@cs.brown.edu (Harry Mamaysky) writes:


>Is there a way for me to find out what line number is currently being
>executed in a c program from within that program?

>Will this method also work in C++?

Here is a method portable across C and C++, which will display the
source file name and the line number within that file where the
statement appears.  __FILE__ and __LINE__ are predefined macros
which are expanded at compile time.

	printf("File %s, Line %ld\n", __FILE__, (long)__LINE__);

Of course, you have to add the printf statements to your code.
I have shown a cast to long and a "%ld" format, because the type
of __LINE__ is not specified, and might be int or long depending
on your implementation.

Alternatively, you could have global variables which you set at
strategic times to __FILE__ and/or __LINE__.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com
Vice Chair, ANSI C++ Committee, X3J16
Newsgroups: comp.lang.c
From: saari@cray.com (Amy Saari)
Subject: curses
Organization: Cray Research, Inc.
Date: 29 Sep 92 10:42:49 CDT


I'm looking for a way to integrate X windows with curses.  Has anyone
out there tried to do anything like this?  Our project intends to
use a client/server model between application and interface server.
The current X stuff works fine - so now can we build a server that
displays using curses?  Any insights would be greatly appreciated.
Please respond directly to me - I don't read this group on a regular
basis - thanks much....

Amy
-- 
==============================================================================
 Amy Saari                                amy.saari@cray.com
 Cray Research, Inc.                        (612) 683-5739  
 Eagan, MN  55121         "Are you sure you want me to take a quality class?"
From: epp@mala.bc.ca (Lorne Epp)
Newsgroups: comp.lang.c
Subject: Re: NO NUMBERS! (or even SHORT INTS!)
Date: 29 Sep 92 01:06:43 GMT
Organization: Malaspina College

In article <tholle16.717718554@ursa>, tholle16@ursa.calvin.edu (Tim Hollebeek) writes:
> hansm@cs.kun.nl (Hans Mulder) writes:
> 
>>In <exuptr.722.717694259@exu.ericsson.se> exuptr@exu.ericsson.se (Patrick Taylor) writes:
> 
>>>But, Jon, what about all my loop variables (i1,i2,i3,i4)  ;-)
> 
>>Better call the i_one, i_two, i_three, i_four, etc.
>>Makes your code much more readable, portable, maintainable, etc.
> 
> 
> NO!  The ANSI standard should specify that you have to call them:
> 
> First_Loop_Control_Variable, Second_Loop_Control_Variable, etc.
> 

Too verbose.  The logical solution is to call them i, ii, iii, iv, etc.
----------------------------------------------------------------------
Lorne Epp                                               epp@mala.bc.ca
Newsgroups: comp.lang.c,comp.lang.pascal,comp.lang.misc
From: peter@ferranti.com (peter da silva)
Subject: Re: SUMMARY: Preferences toward case sensitivity/insensitivity
Organization: Xenix Support, FICC
Date: Mon, 28 Sep 1992 23:42:35 GMT

In article <9226902.9004@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
> If foo and FOO are both used in the same scope then either:
> 	(1) They denote different identifiers, and the compiler issues a
> 	    warning;
> 	(2) They denote the same identifier, but the compiler issues a
> 	    warning; or
>         (3) The compiler issues an error.

I'll buy that, though I'd prefer to have this enforced between scopes for
globals as well. I think this would resolve all remaining complaints about
BOTH case-sensitive and case-insensitive languages, whether you think MAD
and mad and Mad are the same word, or not.
-- 
Peter da Silva                                               `-_-'
Ferranti Intl. Ctls. Corp.                                    'U` 
Sugar Land, TX  77487-5012
+1 713 274 5180                                   Har du kramat din varg idag?
Newsgroups: comp.lang.c
From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
Subject: Re: Strings and integer sizes
Organization: Computer Science, University of Melbourne, Australia
Date: Fri, 2 Oct 1992 19:13:33 GMT

pjh@mccc.edu (P. J. Holsberg) writes:

>Multiple choice question:
>
>A string is stored
>	a. in an array of characters
>	b. in an array of characters terminated with 0
>	c. in an array of characters terminated with '\0'

Well, the answer is:
	d. all of the above

>(T or F) The ANSI Standard for C guarantees that
>	sizeof(short) <= sizeof(int) <= sizeof(long)

True.

-- 
Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
This .signature virus is a self-referential statement that is true - but 
you will only be able to consistently believe it if you copy it to your own
.signature file!
From: apardon@rc1.vub.ac.be (Antoon Pardon)
Newsgroups: comp.lang.c
Subject: Re: 'make' woes (won't catch secondary dependancy)
Date: 2 Oct 92 10:26:46 GMT
Distribution: world
Organization: Brussels Free Universities (VUB/ULB), Belgium

In article <BvFB6o.A1w@news.cso.uiuc.edu>, gbnewby@uxh.cso.uiuc.edu (Gregory B. Newby) writes:
|> 
|> I have a header file that #include's another header file.  I
|> would like for my 'make' to catch whether either of them are 
|> modified.  Here is a very simple example of what goes wrong
|> (of course, what I'm doing is a bit more complicated....hence,
|> just putting "test.o: h1.h h2.h" will work in this example,
|> but will not give me the freedom & capability I need to be
|> happy):
|> 
|> 1% cat makefile
|> .c.o:
|>         cc -c $*.c -I.
|> 
|> test.o: h1.h
|> 
|> h1.h: h2.h

make that

h1.h: h2.h
	touch h1.h

That ought to work

[ stuff deleted ]

|> Thanks!

========================================================================
Antoon Pardon                                        <apardon@vub.ac.be>
Brussels Free University Computing Centre                   02/650.37.16
========================================================================
From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.lang.c
Subject: Re: NO NUMBERS! (or even SHORT INTS!)
Date: 29 Sep 92 23:31:45 GMT
Organization: negligable

In article <tholle16.717718554@ursa> tholle16@ursa.calvin.edu (Tim Hollebeek) writes:
>
>NO!  The ANSI standard should specify that you have to call them:
>
>First_Loop_Control_Variable, Second_Loop_Control_Variable, etc.
>

You have a mixed idiom here, either (new convention):
	FirstLoopControlVariable, SecondLoopControlVariable, etc.
or (older convention)
	first_loop_control_variable, second_loop_control_variable, etc.

but never both.  Of course to save yourself typeing you could
abbreviate some of it:
	FirstLpCtlVr, SecondLpCtrVr, etc.

Now we're getting somewhere!

		-Richard Hartman
		hartman@uLogic.COM

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Extensive studies have shown that 93% of all statistics are meaningless.
From: dmills@accvio.intel.com (Dave Mills)
Newsgroups: comp.lang.c
Subject: Re: can != be used in compound if
Date: 30 Sep 92 15:38:00 GMT
Organization: Intel Corporation
News-Software: VAX/VMS VNEWS 1.41

In article <1992Sep28.194631.25334@julian.uwo.ca> operator@julian.uwo.ca (Operator) writes:
>rnum is a random number generated by random().
>number_set[] is an array of 6 integers.
>
>if (rnum != number_set[1] && rnum != number_set[2] && rnum != number_set[3])
>
>is this if statement correct, if not, what is wrong with it????
> 

I think the problem here is operator precendence.  If my memory serves me,
without K&R in hand, && has higher precendence than !=.  This generates a
perfectly legal C statement, but doesn't do anything like what you expected.
Add a few parens, like this:
	if ((rnum != number_set[1]) && (rnum != number_set[2]) &&
		(rnum != number_set[3]))
and it should work okay.

Dave
-----------------
David Mills
Intel Corporation
dmills@intel.com
Newsgroups: comp.lang.c
From: brown@NCoast.ORG (Stan Brown)
Subject: Re: ++i = i++ ?
Organization: Oak Road Systems, Cleveland Ohio USA
Date: Tue, 29 Sep 1992 01:47:14 GMT

In article <1992Sep28.162405.29567@fzi.de> fzi.de writes:
>I wanted to use the statement: 
>       
>       for (i = 0; i < Count, ++i)
>       { /*any correct c codes*/}
>
>[but i++ seems to do the same as ++i].

The short answer is: ++i and i++, used by themselves as statements, are
exactly the same.  It's where they are used in expressions that they may
make a difference.  For example, this code will put an 'A' in a[2]:
    i = 1;
    a[++i] = 'A';
but this code will put an 'A' in a[1]:
    i = 1;
    a[i++] = 'A';
Either way, after the second semicolon, i will be 2.

As usual, Steve Summit has explaineed this quite well in the FAQ.  See
section 3.  (It's question 3.3 in my copy, which was posted six months
ago, so the question number may have changed.


-- 
Stan Brown, Oak Road Systems                      brown@Ncoast.ORG
Cleveland, Ohio, USA
Newsgroups: comp.lang.c
From: anikzad@symbol.com (Arman Nikzad)
Subject: K&R to ANSI convertor.
Organization: Symbol Technologies, Inc.
Distribution: ALL
Date: Fri, 2 Oct 1992 12:53:34 GMT

Hi everybody, 
             I am faced with a small problem. we are moving towards 
ANSI C/C++, but have tons of K&R style code which we need to convert
to the ANSI format. I was about to write a little program to do this,
then I thought there must be a program that can do this (and do it 
right). If anybody knows of such progam(s) please let us know. 

Thankx in advance !..


Newsgroups: comp.lang.c
From: amorgan@Xenon.Stanford.EDU (Crunchy Frog)
Subject: Re: Stack Overflow ( HELP PLEASE )
Organization: Computer Science Department, Stanford University.
Date: Mon, 5 Oct 1992 04:28:13 GMT

In article <BvMrJ3.22F@news.cso.uiuc.edu> 
  gordon@osiris.cso.uiuc.edu (John Gordon) writes:
>cs125b52@ih-nxt01 (cs125 student) writes:
>
>>     I'm using a recursive function to mimic "floodfill" for SVGA. 
>>Unfortunately, my new function keeps giving me a stack overflow.  How do I
>>increase the stack?  Could anybody give me a hint?  I've tried different
>>memory models and everything else I could think of. 
>
>	extern unsigned _stklen = 64000;

Another alternative is to code a better floodfill algorithm which doesn't
pound on the stack so much.  Sorry, this isn't meant to be a sarcastic
response, but unless you are coding this particular algorithm for a 
particular reason, choosing a different one might be in order.

>John Gordon                        My incredibly witty saying has been 
>gordon@osiris.cso.uiuc.edu         Politically Corrected into oblivion.

C Frog
Newsgroups: comp.lang.c
From: adam@microware.com (Adam Goldberg)
Subject: Re: Is there is (pascal) WITH equivalent in C?
Organization: Microware Systems Corp., Des Moines, Iowa
Date: Mon, 28 Sep 1992 13:04:01 GMT

ray@astro.ocis.temple.edu (Ray Lauff) writes:

>When programming in (sigh) Pascal there is a WITH statement which
>allows all the references to a structure to be referenced without
>repeating the struct variable name.  Is there such a thing in C?
>I don't believe there is, but I may be wrong...

Not really, however, if you have something that looks like this:

typedef struct {
  stuff...
  int x;
} foo, *p_foo;

typedef struct {
  stuff...
  p_foo  foo_struct;
} bar, *p_bar;

typedef struct {
  stuff...
  p_bar bar_struct;
} foobar, *p_foobar;

void xyzzy(p_foobar f)
{
  /* want to access 'x' */

  dosomething(f->bar_struct->foo_struct->x);  
  dosomething2(f->bar_struct->foo_struct->x);  
  dosomething3(f->bar_struct->foo_struct->x);  
  dosomething4(f->bar_struct->foo_struct->x);  
  /* Would work, but if you end up doing 10 things with x, then all those 
   * dereferences take up a lot of time &  space
   */
}
    		

/* On the other hand, doing something like this: */

void xyzzy2(p_foobar f)
{
  p_foo  myfoo = f->bar_struct->foo_struct;

  dosomething(myfoo->x); /* takes up less space */
  dosomething2(myfoo->x); 
  dosomething3(myfoo->x); 
  dosomething4(myfoo->x); 
}
-- 
Adam G.
adamg@microware.com, or ...!uunet!mcrware!adamg
The above is not to be construed in any way as the official or unofficial
statements of Microware, or any Microware employees.
Newsgroups: comp.lang.c
From: rehak@breeze.rap.ucar.edu (Nancy Rehak)
Subject: Re: sprintf
Organization: NCAR / RAP
Date: Thu, 1 Oct 1992 16:47:17 GMT

In article <1af9ctINNiu8@usenet.INS.CWRU.Edu> mxa11@po.CWRU.Edu (Madhavi Ahuja) writes:
>
>Hi Netters
>I have seen sprintf being used in the following ways
>
>1>
>char s1[10];
>char s2[5];
>sprintf(s1, s2);
>
>2>
>sprintf(s1, "ABCD");
>
>The above examples produce the correct result in s1 even
>though the format is missing. Can such a usage result in any serious
>side effects ??
>Thanks
>Madhavi
>ma@acqdev.eeg.ccf.org


Actually, these statements do have a format string.  The second string is the
format string.  It just doesn't, at least in the second example, contain any
format information about following arguments (which is correct since there are
no following arguments).

There are no side effects associated with such usage except the usual concerns
(making sure s1 is large enough, etc.).  However, it is probably more efficient
to use strcpy or strncpy to copy strings.

Nancy Rehak
From: scjones@thor.sdrc.com (Larry Jones)
Newsgroups: comp.lang.c
Subject: Re: unpredictable post-decrement behavior.
Summary: hubris
Date: 4 Oct 92 18:53:31 GMT

In article <1992Oct2.161718.29765@leland.Stanford.EDU>, dkeisen@leland.Stanford.EDU (Dave Eisen) writes:
> While I care very much about C stylistic concerns, I recognize 
> that many of the questions raised are judgment calls. But I have
> to wonder about a programmer who insists on using constructs
> that are not legal C just because he finds them easier to use
> and understand. And then blaming the compiler if it gets it "wrong".

Well, hubris *is* one of the characteristics of great programmers.
Unfortunately, it seems to be the characteristic most easily
assimilated by wannabes, long before it's deserved.  Please
remember, folks: those of you who think you know everything are
really annoying to those of us who do. ;-)
----
Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070
Domain: lawrence.jones@sdrc.com               IBMMAIL: USSDR7DR at IBMMAIL
Archaeologists have the most mind-numbing job on the planet. -- Calvin
From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.lang.c
Subject: Re: NO NUMBERS! (or even SHORT INTS!)
Date: 29 Sep 92 23:36:18 GMT
Organization: negligable

Your friend had better look again at his spaghetti.  If you had
a bunch of labels & jumps, THAT's spaghetti.

The worst you can be accused of is informality.		:)


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Lazy day, Sunday afternoon.			|
Like to get your feet up, watch TV.		|	-Richard Hartman	
Sunday roast is something good to eat,		|	hartman@uLogic.COM
must be lamb to day 'cause beef was last week!	|

Newsgroups: comp.lang.c
From: dooley@helios.physics.utoronto.ca (Kevin Dooley)
Subject: Re: line number in C program
Organization: University of Toronto Physics/Astronomy/CITA
Date: Tue, 6 Oct 1992 20:41:29 GMT

In article <rfries.106@fries_Robert@ub.ub.com> rfries@fries_Robert@ub.ub.com (Robert Fries) writes:
>In article <1992Oct5.193542.11024@cs.brown.edu> hm@cs.brown.edu (Harry Mamaysky) writes:
>
>
>>Is there a way for me to find out what line number is currently being
>>executed in a c program from within that program?
>
>>Will this method also work in C++?
>
>>Harry.
>
>>hm@cs.brown.edu
>
>
>No.

Well, there IS a broot fors way.  After every single statement in your C
program, you put in a line like:
	fprint(stderr, "DEBUG: line number %d\n", __LINE__);

the __LINE__ macro gets processed at compile time and replaced with the
line number.  Another similar useful macro is __FILE__ which, obviously,
is the name of the file which contains this bit of code.  This should
also work with c++.  However, a better way to do this is to run your
code under a symbolic debugger.  The solution above is rather inelegant.

Kevin
From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
Newsgroups: comp.lang.c
Subject: Re: Untyped pointer arithmetic
Date: 2 Oct 92 06:38:42 GMT
Organization: Comp Sci, RMIT, Melbourne, Australia

In article <1992Oct1.125431.11707@blaze.cs.jhu.edu>, wilson@gauss.cs.jhu.edu (Dwight Wilson) writes:
: In article <14813@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
: >So it is syntactically legal to do
: >
: >	void *p, *q;
: >	ptrdiff_t d;
: >
: >	d = (char*)q - (char*)p;
: >
: >Whether that makes sense is up to you.
: 
: Not quite.  This is only a legal pointer operatin if p and q point 
: to members of the same array, or either is the address of the first 
: element past the the end of an the array.  

That is what I meant.  I did not mean "it is up to your personal taste
whether you _think_ this makes sense" but "it is your _responsibility_
to _make sure_ this makes sense".  If something makes sense, it makes
sense, whether someone likes it or not.

-- 
RMIT policy requires the use of Gender Inclusive Language in all publications
and in all information conveyed to students, staff, and potential job
applicants.  Lapses into English are the sole responsibility of the author.
The Constitution of Australia does _not_ guarantee Freedom of Speech.
Newsgroups: comp.lang.c
From: ghuntres@nyx.cs.du.edu (Gary  huntress)
Subject: Problem using fseek
Summary: cant rewind character by character
Keywords: file operations
Organization: University of Denver, Dept. of Math & Comp. Sci.
Date: Fri, 2 Oct 92 03:08:09 GMT


Is there any reason why the following wont work (IBM PC w/ msc 6.0)
fh=fopen("foo.dat","a");
if(fh==NULL) exit(-1);
fseek(fh,-5L, SEEK_CUR);
It just sits at EOF!  It does not rewind.

Maybe I can give a better description of what I'm trying to accomplish.
I've got a long unstructured activity log called by many procedures
The contents of each line (i.e. number of entries ) will vary 
depending on the message that is written:

  1024  TIMECODE ALTITUDE SPEED ERRORCODE
  2020  TIMECODE BUS_VOLTAGE BUS_TEMPERATURE ONLINE TESTCODE
  2022  COMMAND COMMAND_STAT COMMAND_QUEUE RESULT

hopefully you get the idea.  The first string will identify the format 
of the rest of the line.  I want to open the file and parse the LAST line

I figured that the best way to do that would be to open in append mode, 
moving backwards looking for the last \n and then read in strings.

Questions:

  1)  Can I seek backwards through a file opened for append?
  2)  Is there an incredibly obvious solution to this problem 
      that I completely overlooked? 

mucho thanks,
Gary Huntress          while(TRUE){edit(); compile(); link(); run()}D
C

Newsgroups: comp.lang.c,comp.lang.c++