🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.msdos.programmer
3 messages
3 total messages Started by Seth Chaiklin Fri, 08 Jan 1993 13:56
structures >64K
#7529
Author: Seth Chaiklin
Date: Fri, 08 Jan 1993 13:56
72 lines
2435 bytes
I am having problems making a 'huge' struct.  As some of you may
remember from last month, I was asking about how to make arrays
over 64K.  Well now I am trying (rather unsuccessfully) to
achieve the following:

(a) initialize a structure that is about 80K
(b) have that structure be global.

The structure itself is not very complicated:

struct yynew {
int current;
int advance;
};

and the initialization is just small integers

yycrank[] = {1,2,3,4,0,175,0,1,175...};


And it all works just fine as stated, provided the initialization is under
64K.  But I want to use about 40,000 integers in initializing this
structure, and that is where my problem begins.  

I cannot figure out how to declare yycrank to be a 'huge' structure in
Turbo C 2.0.

I can't seem to be able to declare yynew to be huge.

For example:

typedef struct huge yynew {
int current;
int advance;
} YYNEW;

gives a "structure or union syntax error "

And if I try something like:

YYNEW huge yycrank;       /* conflicting type modifiers  - fair enough */

huge YYNEW yycrank;      /* syntax error */

Ok -- so I get the idea (by implication) from the Turbo C manual that 
I have to use a pointer to get a big structure.  So I try something like this:

YYNEW  *yycrank;
yycrank = (YYNEW huge *) farmalloc(20000L * sizeof(YYNEW));

Well that will compile if it is placed inside of a function (though the 
compiler (rightfully) complains about a suspicious pointer conversion.

But if I try to compile this globally then I get these errors

   Declaration needs type or storage class
   Type mismatch in redeclaration of 'yycrank'
   Illegal initialization

plus the warning:

   Suspicious pointer conversion


Aaarrrggghhh!  Given that it is possible to do all this if I am working
under 64K.  Then I would assume that there must be a way to allocate
memory for a structure that is over 64K.  But my various trials and
errors have been discouragingly unsuccessful.  Advice appreciated.

Cheers,
  Seth
  psykseth@aau.dk
Re: structures >64K
#7531
Author: Harvey G Shulman
Date: Fri, 08 Jan 1993 15:35
51 lines
1939 bytes
To: psykseth@aau.dk
Subject: Re: structures >64K
Newsgroups: comp.os.msdos.programmer
In-Reply-To: <1993Jan8.135612.14930@aau.dk>
Organization: The Ohio State University
Cc: 
Bcc: 

Seth:  the code below compiled and ran without error under
turbo c's huge model.  Make sure you select this model on
the compiler option menu.  

It would probably work as well under the
large model with the pointer declaration changed to
yynew  huge *yycrank, j;

I wasn't able to come up with a good way to initialize the
allocated records but the technique below of initializing the
fields of another record, j, and then assigning it to the record
pointed to by yycrank seemed to work.


#include  <stdio.h>
#include  <stdlib.h>
#include  <alloc.h>

void main()
{
int  i;
typedef struct yynew {int current, advance;} yynew;
yynew  *yycrank, j;

/* in the allocation statement I could not see why you used 20000L.
   after all 20000 is 20000, isn't it? */

yycrank = farmalloc(20000 * sizeof(yynew));
for (i = 0; i < 20000; i++)
 { j.current = 0;
	j.advance = i;
	*(yycrank+i) = j ;
 };
}
 in the above loop I tried several variants of assignment to the
 fields of yycrank's records without success.  Maybe someone else can
 describe how to do such things as   *(yycrank+i).current = 0
 

-- 
Harvey Shulman
Ohio State University, Dept of Psychology
614 292-2759 / h.shulman@osu.edu
Re: structures >64K
#7537
Author: Ian D. Gay
Date: Fri, 08 Jan 1993 17:54
12 lines
947 bytes
hshulman@magnus.acs.ohio-state.edu (Harvey G Shulman) writes:

>/* in the allocation statement I could not see why you used 20000L.
>   after all 20000 is 20000, isn't it? */

NO! You want to be very sure that the following multiplication is done 
with longs! C does _not_ do 16x16 bit => 32 bit multiplication. Are 
you sure you really allocated as much memory as you thought?



>yycrank = farmalloc(20000 * sizeof(yynew));
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads