HDTenEightyP/NetNews huggingface dataset:
Organization: The American University - University Computing Center
Date: Mon, 5 Oct 1992 18:59:44 EDT
From: Kayvon Z. Sadeghi <KSADEGH@auvm.american.edu>
Newsgroups: comp.lang.c,comp.lang.c++,comp.std.c,comp.std.c++
Subject: NULLing a pointer and INT 0x1c

Hi guys,

If this is not the right place to ask this just skip this, but compare to what
I saw in this group, I thought this should be the right group.
I have two problems:
1- how do you change the value of a pointer passed to a subroutine? It seems
to me like you can do almost anything with it except changing the value
to NULL. This is what I mean:

pass(struct something *p){
         p=NULL;
}

main(){
      struct something *apointer;

      pass(apointer);
}


I tried everything, but no success.


2- I am using the intrrupt 0x1c to print something in graphic mode.
Something like this:


void interrupt pr(int x,int y){
     disable();
     outtextxy(x,y,<the time>);
     enable();
}


main(){
setvect(0x1c,pr);
.
.
.
}


But, it crashes after a while. Eventhough, the time is printed at the right
coordinate, the system apparently goes down. My guess is that I have to
somehow, save the registers before getting into the pr and restore them after
getting out. But I can't figure out how.


Any help is appreciated.

k1
---
------------------------------------------------------------
KAYVON Z. SADEGHI                  K.SADEGHI@IEEE.ORG
VOICE: 202/244-0789
From: ark@alice.att.com (Andrew Koenig)
Newsgroups: comp.lang.c
Subject: Re: Probably a simple realloc() question
Date: 2 Oct 92 02:54:59 GMT
Article-I.D.: alice.23779
Reply-To: ark@alice.UUCP ()
Organization: AT&T Bell Laboratories, Murray Hill NJ

In article <358@ulogic.UUCP> hartman@ulogic.UUCP (Richard M. Hartman) writes:

> We aren't suggesting it should be forced to return successfully, we
> are suggesting that it be forced to do it's job.  There is no reason
> for downsizing a dynamically-allocated block of memory to fail.

Sure there is.

Suppose you're implementing C on top of an operating system that
already provides malloc and free but not realloc.  Suppose further
that you want to make those two facilities directly available to
your users rather than putting another layer on top of them; that's
what your users expect.

Suppose further that your system provides no way to shrink the size
of an allocated block.  If your user requests such shrinkage, you
really have only two choices:

	1. Don't return any memory to the system, but lie and tell
	   the user you did, or

	2. Allocate new memory, copy the stuff, then free the old.

While I won't argue that (2) is always the best strategy, is is
surely best sometimes.  The reason is that if you take a big area
and turn it into a tiny one, you use a little extra memory for a
while but then make a whole bunch of memory available for reuse

But that implies that realloc may sometimes fail.  Oh well, that's life.
-- 
				--Andrew Koenig
				  ark@europa.att.com
Newsgroups: comp.lang.c
From: cpcahil@virtech.uucp (Conor P. Cahill)
Subject: Re: Freeing dynamic allocated memory
Organization: Virtual Technologies Inc.
Date: Mon, 5 Oct 1992 10:36:56 GMT

In article <92278.164951U37956@uicvm.uic.edu>, <U37956@uicvm.uic.edu> writes:
> Suppose I dynamically allocated a chunk of memory using malloc() in a function,
> but I do not free it when exiting the function. Will the system automatically
> do the garbage collection for me? If not , can I use the original data in the
> memory if the function is re-entered ?
> 

memory allocated by malloc() is only automatically cleaned up (garbage
collected) when the program exists. If you have a function that allocates
memory and then does not free it, you have created what is typically
referred to as a memory leak.  This is because the function will use 
more memory each time it is called and the memory cannot be reused. 

If you want to use the same memory area through several calls to the same
function, you should maintain a static pointer to the data area.  The
following function does just that (not code was not compiled, you mileage
may vary):

	myfunc()
	{
		static char	* data;

		if( data == NULL )
		{
			data = malloc(xxx);
			if( data == NULL )
			{
				return(-1);
			}
		}
		do real stuff with data
	}



-- 
*** SENTINEL(tm) The ultimate Debugging Environment - email for more info ***

Conor P. Cahill              (703)430-9247            cpcahil@virtech.vti.com
Virtual Technologies, Inc.  46030 Manekin Plaza          Dulles, VA 20166 
Newsgroups: comp.lang.c
From: djaschbr@iastate.edu (David J Aschbrenner)
Subject: Determining variable type at run-time
Organization: Iowa State University, Ames, IA
Date: Tue, 29 Sep 1992 21:36:15 GMT


I am curious as to whether it is possible to do something like the following:

main()	{
	int i;

	scanf("%d", &i);
	switch(i)	{
		case 0:
			char a;
			break;
		case 1:
			int a;
			break;

		/* other cases */
	}
	/* rest of program which does something with a */
}

Is this possible? (I do need 'a' to have scope throughout main())
If I can't do this, is there another way to accomplish my goal?

			Thank you,
			David Aschbrenner
From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.lang.c
Subject: argc & argv (was: Re: Microsoft C 7.0 Problem ... NOT!)
Date: 29 Sep 92 21:45:04 GMT
Article-I.D.: ulogic.314
Organization: negligable

I know a lot of folks who have gotten into the habit of
using "ac" and "av" instead of "argc" and "argv".  And
the war against carpal-tunnel syndrome marches on.....

		-Richard Hartman
		hartman@ulogic.COM

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Practice random kindness and senseless acts of beauty.
From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.lang.c
Subject: Re: unpredictable post-decrement behavior.
Date: 1 Oct 92 18:01:02 GMT
Organization: negligable

I had thought that postincrement was guaranteed to be evaluated
after the expression it was found in was evaluated.

Apparently I was wrong.

However, even if I had been right, the example given would have
had problems since the expression it was in was surrounded by
parens separating it from other references to the same variable
surrounded by their own parens.  Which half of the division
occurred first is not specified (although I think it is usually
left-to-right) and we could still come up w/ compiler dependant
inconsistancies.

However, apparently when the postincrement is executed apparently
does NOT follow my original impression and the whole thing gets
screwed up seven ways from sunday because of this.

Is it only in the new ANSI standard that this became undefined,
or would I have been wrong in a K&R compiler too?

		-Richard Hartman
		hartman@ulogic.COM

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
"Nobody has ever had a sexual fantasy about being tied
 to a bed and ravished by somebody dressed as a liberal."    -P.J. O'Rourke

Newsgroups: comp.lang.c
From: silvia@rcf.rsmas.miami.edu
Subject: multiple data segments
Reply-To: silvia@rcf.rsmas.miami.edu
Organization: RSMAS
Date: Tue, 29 Sep 92 00:17:33 GMT

Does anyone now how i can multiple data segments without having to go to the huge memory model? I have tried several different ways and all of them give me erros. Any help would be grately appreciated. Please e-mail your response. Thanks.

            Manolo
From: elliot@Wellspring.COM (Elliot H. Mednick)
Newsgroups: comp.lang.c
Subject: Common C errors (was Strange memory allocation...)
Distribution: world
Date: Sun, 27 Sep 92 01:43:48 GMT
Organization: Wellspring Solutions, Sutton, MA.
Reply-To: elliot@Wellspring.COM

In article <1992Sep24.150734.17035@midway.uchicago.edu> pynq@midway.uchicago.edu writes:
 > No, no, no!  The most common error in C programming is doing:
 > 
 >         scanf("%d",i);
 > 
 > instead of
 > 
 >         scanf("%d",&i);

A common (maybe not THE most common, but close) error in C (reason #215
that I wish the general computing community would allow me to program in
Some Other Language and not laugh me out of an interview for knowing PL/1)
is:

b == a;            /* an attempted assignment */

This statement does nothing, but cannot be flagged as a warning.

(In case anyone cares, reason #1 is there _isn't_ a book called
"Modula II Puzzle Book", or "Pascal Puzzle Book", or "PL/1 Puzzle Book".)

(And while I'm on a roll, reason #2 is that C is _not_ portable.)
From: delz3530@csd4.csd.uwm.edu (Andrew J.G. Delzer)
Newsgroups: comp.lang.c
Subject: linked list in array of struct
Date: 29 Sep 1992 01:43:13 GMT
Organization: University of Wisconsin - Milwaukee
Distribution: usa
NNTP-Posting-Host: 129.89.7.4
Originator: delz3530@csd4.csd.uwm.edu


     Could anyone in netland help me with a C problem I have
  run into.  I am in need of placing a linked list in an 
  array of stuctures, and all my C boots give very very brief
  examples.  An outline of what I have follows;

	...
	...
	struct node
	{
	  char SN[20];
	  struct node *next;
        }

	struct Table
	{
	  char CourseTitle[20];
	  struct node *StudentName[20]
        }

	...
	...

	main()
	{
	  static struct Table ClassTable[100];
          ...
	  ...
        }
        
      The table of data would look like;

	  ClassTable[0].CourseTitle =  Math001
	  ClassTable[0].StudentName =  Smith Jon
				    =  Dow Jane
				    =  Hunt Mike

          ClassTable[1].CourseTitle =  English100
	  ClassTable[1].StudentName =  Washington George
				    =  Lovelace Linda

     I can place the CourseTitles in the table just fine, but I 
 am totally lost on how to setup the link list, place the first
 name in the list and how to place all other names in the list.
 If you can understand what I'm in search of I would be very greatfull
 for your help.

             Andrew J.G. Delzer
             delz3530@csd4.csd.uwm.edu

Newsgroups: comp.lang.c
From: hjv@phil.ruu.nl (Hendrik Jan Veenstra)
Subject: Re: Common C errors (was Strange memory allocation...)
Organization: Department of Philosophy, University of Utrecht, The Netherlands
Date: Sun, 27 Sep 1992 11:03:56 GMT

elliot@Wellspring.COM (Elliot H. Mednick) writes:

>In article <1992Sep24.150734.17035@midway.uchicago.edu> pynq@midway.uchicago.edu writes:
>A common (maybe not THE most common, but close) error in C (reason #215
>that I wish the general computing community would allow me to program in
>Some Other Language and not laugh me out of an interview for knowing PL/1)
>is:

>b == a;            /* an attempted assignment */

>This statement does nothing, but cannot be flagged as a warning.

How about the reverse:
    if( a = b )
    {...
obviously intended to be '==' instead of '='. I've lost too many hours
finding this one... :)


--
Hendrik Jan Veenstra                            hjv@phil.ruu.nl
Department of Philosophy              -------------------------------------
University of Utrecht                     All opinions expressed above
The Netherlands                               are pure coincidence 
Newsgroups: comp.lang.c
From: vasco@jessica.bvl.pt (Antonio Vasconcelos)
Subject: Comlex data structures on term emulation - HELP 
Reply-To:  (Antonio Vasconcelos)
Organization: Bolsa de Valores de Lisboa 
Date: Tue, 6 Oct 1992 12:40:44 GMT

Hello all, this is my first post in comp.lang.c (and in the Internet)

I intend to write a terminal emulator using Turbo C 2.0.
I think about it a while and get to the conclusion that
the better method of translating incoming ESC sequences
is to define a LARGE array like this:

	struct table
	{
		char esq-seq[8];
		void *execfunction();
	};

	struct table Tab[LARGE_ARRAY];

Whowever, with this method my program will have to know about
the length of ALL possible ESC sequences and that kind of
processing will take more time that I could spend.

I'd like to use something like: *Tab[char1][char2][char4] where
char1, char2 and char4 are the characters that come next to the ESC
char.

Can anyone see a way of doing this ?

Any help will be wellcome, thanks in advance


    ///////////////////////
  /// vasco@jessica.bvl.pt ///
///////////////////////
Newsgroups: comp.lang.c
From: andy@research.canon.oz.au (Andy Newman)
Subject: Re: problem with format of while, for if, and nested ifs
Organization: Canon Information Systems Research Australia
Date: Thu, 1 Oct 1992 01:29:20 GMT

hartman@ulogic.UUCP (Richard M. Hartman) writes:
>Now, let's see about syntax problems...
>
>>while ( condition )
>>   {
>>   for ( condition )
>
>//- problem: syntax for "for" is "for (statement; condition; statement)"
>//		a simple "for (condition)" may have unpredictible results
>

Interesting "for" syntax, I always thought it was...

	"for ( expression; expression; expresion )"

With your one does that mean I can "for ( for (;;);  ; x ; if (y ) z )" ?
					          ^ big ambiguity there!
(Big smiley :-)

-- 
Andy Newman (andy@research.canon.oz.au)		"int - God's own type"
Newsgroups: comp.lang.c
From: xiong@fzi.de (Xiong Xun)
Subject: ++i = i++ ?
Reply-To: fzi.de
Organization: Forschungszentrum Informatik (FZI), Karlsruhe, Germany
Date: Mon, 28 Sep 1992 16:24:05 GMT

I wanted to use the statement: 
       
       for (i = 0; i < Count, ++i)
       { /*any correct c codes*/}

Then I made a typo by writting down "i++" instead of "++i" ...

The result: both of them are functioning (offer the same result)!

Someone there could enlighten me on this?
From: ajayshah@almaak.usc.edu (Ajay Shah)
Newsgroups: comp.lang.c
Subject: Function pointer problem
Date: 27 Sep 1992 19:39:56 -0700
Organization: University of Southern California, Los Angeles, CA
NNTP-Posting-Host: almaak.usc.edu

/* Consider this simple program.  It defines an abstract "Observation"
and a function type named obsprinter who is supposed to print out
an Observation.

There is a function elsewhere which consumes a obsprinter function.
It is called somefunction.

------- start of program ------- */
typedef void *Observation;
typedef void (obsprinter)(Observation);
void somefunction(Observation x, obsprinter *f);

void floatpairprinter(float *x)
{
    printf("%f %f\n", *x, x[1]);
}

int main()
{
    float *y;
    somefunction((Observation) y, /* (obsprinter) */ floatpairprinter);
    return 0;       
}
/* ------ end of program -----

This main program wants to think of a float * as being an Observation.
This is fine when casting y when handing it to somefunction.

That does not work with floatpairprinter.  If I cast it, gcc rejects
it as a hard error.  If I don't cast it, things work, but gcc emits
a warning.

Is there a way to do this right?  I can see his problem: he wants a
function which consumes a Observation, but I'm giving him a function
which consumes a float *.  How do I reassure him all is well?

        -ans.
*/

-- 
Ajay Shah, (213)749-8133, ajayshah@usc.edu
Newsgroups: comp.lang.c
From: scs@adam.mit.edu (Steve Summit)
Subject: Re: unpredictable post-decrement behavior.
Organization: none, at the moment
Date: Sat, 3 Oct 1992 07:04:17 GMT

In article <1992Oct2.121045.24203@alw.nih.gov>, Gregory Humphreys
(gregh@alw.nih.gov) writes:
> In article <1992Oct2.114217.384@rz.uni-karlsruhe.de>, "hans friedrich steffani" <GM08@DKAUNI2.BITNET> writes:
>> herzog@ux5.lbl.gov (Hanan M. Herzog) writes:
>>>              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++'.
>>
>> i think ppl who wrote code like this should be fired. this is no
>> defensive prgramming, difficulty to understand an perhaps in the
>> result compilerdependet. so dont use constructs like this.
>
> Well, Hans, I'm glad you are the authority on aesthetic C constructs.
> Personally, as I program C every day at my job, I use constructs like the
> above all the time.  I find them much easier to use and understand.  One of 
> the beauties of C is it's compactness, and writing code with the n++ on the
> next line sort of defeats the purpose.

If people don't start paying attention I may get cross.

The code fragment being so endlessly discussed of late (the one
preceded by ">>>" above) really, truly does yield undefined
behavior, for reasons which have been adequately and somewhat
exhaustively enumerated.  Programmers write such code at their
peril.

Source compactness is probably second only to efficiency as the
false virtue which has led to the most numerous and grotesque
transgressions against portability, maintainability, and decent
programming sensibilities.  Though good code is often compact, it
is utterly specious to suppose that code can be improved merely
by reducing its character count.  Worry about good style, and
conciseness and compactness will follow; not the other way around.

					Steve Summit
					scs@adam.mit.edu
Newsgroups: comp.lang.c
From: atbowler@thinkage.on.ca (Alan Bowler)
Subject: Re: Probably a simple realloc() question
Organization: /etc/organization
Date: Tue, 6 Oct 1992 20:14:32 GMT

In article <1992Oct2.151657.24186@blaze.cs.jhu.edu> wilson@rhombus.cs.jhu.edu (Dwight Wilson) writes:
>
>You should clear errno on a successful call.  Note that under
>Unix most calls do NOT clear errno, so the value is not
>meaningful after a successful call.  This implementation would
>be an expection to that rule.
>
No, the standard forbids library functions from setting errno to zero.
From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.lang.c
Subject: Re: 'make' woes (won't catch secondary dependancy)
Date: 1 Oct 92 21:46:42 GMT
Organization: negligable

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):

Well, you don't want the easiest & surest way out, huh?....

>
>1% cat makefile
>.c.o:
>        cc -c $*.c -I.
>
>test.o: h1.h
>
>h1.h: h2.h
    touch h1.h                <<<<<<<<<<<-------------  previous dependancy
                                                      (test.o:h1.h) will not
                                                      be triggered unless
                                                      h1.h get's it's date
                                                      changed.


Of course, a smarter make would make a special case for a .h.h rule
that simply adds the dependant files wherever it finds the target
.h file in the dependancy, but I don't know of any make that does 
this.  You could always take the GNU make sources and hack this
capability into it.



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Philosopher and plowman			|
each must know his part			|	-Richard Hartman	
to build a new mentality		|	hartman@uLogic.COM
closer to the heart!			|
From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
Newsgroups: comp.lang.c
Subject: Re: Untyped pointer arithmetic
Date: 1 Oct 92 06:39:40 GMT
Organization: Comp Sci, RMIT, Melbourne, Australia

In article <1ad47fINNgl0@gap.caltech.edu>, mcs@goblin.caltech.edu (Martin Shepherd) writes:
> Is there any way to do anonymous pointer arithmetic portably?

Use char*

I am serious.  What are the differences between char* and void* ?
You can assign a value of type void* to a variable of any other
data pointer type without a cast (think "malloc doesn't need a cast").
You can assign a value of any other data pointer type to a
variable of type void* without a cast (think "passing to a void *
parameter of a prototyped function doesn't need a cast").
You cannot dereference a pointer of type void *
(think "there are no void objects").
You cannot do arithmetic on values of type void *
(think "void has no size").

But void* and char* must have the same representation (this is necessary
because Classic C didn't have void*; malloc() used to return char *, and
so on for all the functions with void* arguments and results).

So it is syntactically legal to do

	void *p, *q;
	ptrdiff_t d;

	d = (char*)q - (char*)p;
	q = (void*)((char *)q - d);
	p = (void*)((char *)p + d);

Whether that makes sense is up to you.

Yes, ANSI C _could_ have been defined to make void* arithmetic
identical to char* arithmetic, but that would have been less useful
because you wouldn't have had any way of saying "I DON'T intend to
do arithmetic on these pointers".

If you are doing a lot of arithmetic on void*, it is better to use
char* in the first place, as you'll save yourself a lot of casts.
Best of all is to rethink the problem.  Do you _really_ need to do this?
-- 
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.
From: murthy@novell.com (M.D. Srinivas Murthy)
Newsgroups: comp.lang.c
Subject: Re: Algorithm for Day-Of-Week NEEDED
Date: 2 Oct 92 22:00:14 GMT
Organization: Novell Inc., San Jose, Califonia

In article <Bv47oy.MC5@mentor.cc.purdue.edu> bjackson@mentor.cc.purdue.edu (Ben Jackson) writes:
>In article <281@ulogic.UUCP> hartman@ulogic.UUCP (Richard M. Hartman) writes:
>>You might want to use the isleap() macro instead of the literal
>>year%4 the code currently uses.  Although I think that was what
>>
>>if it doesn't, it should, I am certain about the "except if divisible
>>by 100"  I am not so certain about the second, "un-exception" when
>>divisible by 400.  can anyone confirm?
>
>if 4, but not 10, but if 400, but not 1000, but if 4000... obviously only
               ^^                      ^^^^         ^^^^
I think you really meant " if 4, but not 100, but if 400, but not 10000, but
if 40000....."
From: bjackson@mentor.cc.purdue.edu (Ben Jackson)
Newsgroups: comp.lang.c
Subject: Re: ++i = i++ ?
Date: 28 Sep 92 20:54:36 GMT
Organization: Purdue University Computing Center

In article <1992Sep28.184140.4116@kpc.com> hollasch@kpc.com (Steve Hollasch) writes:
>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*/}
>    I'll assume that you made a typo here and really meant to say
>
>        for (i=0; i < Count; ++i)
>                           ^ A comma here is a syntax error.
>
>    The third expression here can be either "++i" or "i++".  This is
>equivalent to the following while loops:
>
>        i = 0;                           i = 0;
>        while (i < Count)                while (i < Count)
>        {   <statement list>;            {   <statement list>;
>            ++i;                             i++;
>        }                                }

Aieee!  Those while() loops are *NOT* the same as the for(;;) statement!

Imagine:

for(i = 0; i < Count; ++i)               i = 0;
{					 while(i < Count)
	continue; 			 {
}					 	continue;
					        ++i;
					 }

  ^^^ perfectly ok, ++i still executed.   ^^^ infinite loop.

This is a very important distinction. :-)

\\_//
 o o    Ben Jackson
< ^ >   bjackson@mentor.cc.purdue.edu
 \~/         ...@glia.biostr.washington.edu
  V     "Natural laws have no pity."
Newsgroups: comp.lang.c