Member Avatar for GreenDay2001

Well, I am writing a program in which i need these global variables. However when I compile, ile I get a message To Much Global Data in This File.

I have no other option, i.e. use pointers and all, cause there are certain restrictions to as per my teacher said.

So is there any method to solve this. Also whats the limit of the global data. I am supposed to use Borland C++ 3.1

#define MAX_CAPACITY 500
int  bookId[MAX_CAPACITY];
char bookName[MAX_CAPACITY][50];
char bookAuthor[MAX_CAPACITY][50];
int  boolIssue[MAX_CAPACITY];           // 0, 1
char dateIssue[MAX_CAPACITY][12];       // dd-mm-yyyy
char dateReturn[MAX_CAPACITY][12];      // dd-mm-yyyy
int  issuedTo[MAX_CAPACITY];
int  issueToClass[MAX_CAPACITY];
char issueToSection[MAX_CAPACITY];
int  boolMember[MAX_CAPACITY];          // -1, 0, 1

The problem is probably Borland 3.1 - I see no reason why this code shouldn't compile in either C or C++ (it worked fine using Comeau online in strict mode).

I would reccomend talking to your teacher and asking why you are being taught an outdated version of the language (Borland 3.1 doesn't support many of the features which are a part of today's standard C++)

Aside from this, what exactly requires you to use so many global variables? there is more than likely another way to redesign your program without using global variables at all.

commented: Right Advice ~~ SpS +3

Old borland compilers starting with Turbo C had that problem -- its 16-bit compiler will not allow more than 64K worth of data in any one *.c or *.cpp file. If you need more global data than that you have to split it up into two or more files.

commented: :) ~~ SpS +3
Member Avatar for GreenDay2001

The problem is probably Borland 3.1 - I see no reason why this code shouldn't compile in either C or C++ (it worked fine using Comeau online in strict mode).

I would reccomend talking to your teacher and asking why you are being taught an outdated version of the language (Borland 3.1 doesn't support many of the features which are a part of today's standard C++)

Aside from this, what exactly requires you to use so many global variables? there is more than likely another way to redesign your program without using global variables at all.

Well, I as well as my teacher is well awared of this fact that Borland C++ 3.1 does not support today's standard c++. We are using this outdated version cause our syllabus says this.

Uh.. I need these great number of global variables because we are not allowed to use Pointer, Objects and other things....only function and arrays, probably because we haven't covered these topics in school.

The maximum limit for globals in any program should be ZERO.
Globals are evil and should not generally be used.

The maximum limit for globals in any program should be ZERO.
Globals are evil and should not generally be used.

In 16-bit C programs it is often necessary to use globals because of the limited available stack space and Vishesh is not allowed to use pointers. I used to just put global data into its own *.c file and use as many *.c files as necessary.

So is there any method to solve this. Also whats the limit of the global data. I am supposed to use Borland C++

The limit is I think 64K of memory.

One solution you can try is to create seperate header files with each header file containing variables having less than 64K of size. For eg.
Contents of header file 1

#define MAX_CAPACITY 500
int  bookId[MAX_CAPACITY];
char bookName[MAX_CAPACITY][50];
char bookAuthor[MAX_CAPACITY][50];
int  boolIssue[MAX_CAPACITY];           // 0, 1

Contents of header file 2

char dateIssue[MAX_CAPACITY][12];       // dd-mm-yyyy
char dateReturn[MAX_CAPACITY][12];      // dd-mm-yyyy
int  issuedTo[MAX_CAPACITY];
int  issueToClass[MAX_CAPACITY];
char issueToSection[MAX_CAPACITY];
int  boolMember[MAX_CAPACITY];          // -1, 0, 1

And in your program use :

#include <header1.h>
#include <header2.h>

int main( )
{
   // code
}

In 16-bit C programs it is often necessary to use globals because of the limited available stack space and Vishesh is not allowed to use pointers. I used to just put global data into its own *.c file and use as many *.c files as necessary.

Just goes to show that homework assignments that are stupidly constructed teach all the wrong things :)
Personally I've never encountered during my studies an assignment where we weren't allowed to use things that hadn't been part of the curiculum (yet).
Teachers encouraged independent study and experimentation, and would at most look a bit miffed if you found a solution that was easier than the one intended using a different (but correct) technique than intended.

Member Avatar for GreenDay2001

Just goes to show that homework assignments that are stupidly constructed teach all the wrong things :)
Personally I've never encountered during my studies an assignment where we weren't allowed to use things that hadn't been part of the curiculum (yet).
Teachers encouraged independent study and experimentation, and would at most look a bit miffed if you found a solution that was easier than the one intended using a different (but correct) technique than intended.

Well, i am in 11th standard and probably not doing my engineering degree. We have Arrays, Functions and other basics in c++ this year. The actual C++, i.e. the OOP concepts, pointers etc.. will start by April, the new session and this is our Annual Project.

Just because it's not part of your curiculum doesn't mean you shouldn't be allowed to use it if you do so correctly.

But with education being ever more dumbed down (and now teachers being dumbed down as well it seems) maybe teachers no longer know anything except what's in their own textbooks either...

Member Avatar for GreenDay2001

Just because it's not part of your curiculum doesn't mean you shouldn't be allowed to use it if you do so correctly.

I asked him and he refused, saying that we'll do that after 3 months. Hope I was able to use pointer, objects and all...my life would have become more easier. But freaking out with just functions and array is fun, headache and all. In other words less resources more work;)

But with education being ever more dumbed down (and now teachers being dumbed down as well it seems) maybe teachers no longer know anything except what's in their own textbooks either...

No comments on it.....but i must say that my teacher is really very good.

One solution you can try is to create seperate header files with each header file containing variables having less than 64K of size. For eg.

That shouldn't matter one bit. The header files are pulled into the source before compilation and therefore splitting them up doesn't influence the footprint of the compilation unit.

It would only matter if for some reason a header file was too complex for the preprocessor to handle, but when split into smaller chunks can be handled.
That however isn't the case here.

That shouldn't matter one bit. The header files are pulled into the source before compilation and therefore splitting them up doesn't influence the footprint of the compilation unit.

It would only matter if for some reason a header file was too complex for the preprocessor to handle, but when split into smaller chunks can be handled.
That however isn't the case here.

agree -- you only put the extern declarations in header files, not the actual instances of the objects. The actual instances of the data must not exceed 64K in any one *.c file.

and even if you put the instances in there, if you include all the header files it still won't matter one iota.

That shouldn't matter one bit. The header files are pulled into the source before compilation and therefore splitting them up doesn't influence the footprint of the compilation unit.

agree -- you only put the extern declarations in header files, not the actual instances of the objects. The actual instances of the data must not exceed 64K in any one *.c file.

Bleh...it was just a desperate idea...no need to beat me up that badly..:D

Vishesh, what you can do is that, you can use files instead of variables i.e. using files for reading as well as writing data. Though it would be really inefficient to do much of a reading and writing, you can provide the solution without using pointers or by declaring excessive variables.

And btw, I think this was the actual intent of the problem statement, to make you people to use files.

Member Avatar for GreenDay2001

Bleh...it was just a desperate idea...no need to beat me up that badly..:D

Vishesh, what you can do is that, you can use files instead of variables i.e. using files for reading as well as writing data. Though it would be really inefficient to do much of a reading and writing, you can provide the solution without using pointers or by declaring excessive variables.

And btw, I think this was the actual intent of the problem statement, to make you people to use files.

Well, thats the problem. I am not supposed to anything, pointer, objects, file streams etc etc... Only functions and arrays.

It is because I am in 11th and pointer, classes and objects, file streams etc are not part of this year. So I can't use it.

But I dont know why have I been given such topic in which i just have to use functions and arrays, which are not sufficient. Atleast they had included Pointers this year, so that I could make it in C style.

Bleh..then I can see only one solution -- try to keep the value of max_enteries as low as possible. Try out with different values of max and see which of those doesnt flag the error.

Considering the kind of restrictions imposed on you, I am pretty sure than the size of 500 is not required or is not mentioned in the problem statement. Just keep the record of 50 books and it should work out to be fine.

But if your professor is still adamant on 500 then....may god be your saviour. I'll pray for you.... ;)
_()_

Member Avatar for GreenDay2001

Well, i have already done this, today only, 200 works well. But I think its too large and will make program big so keeping it even smaller is better.

But one thing, does situations come in engineering....where there is no other option (right now i had i could change 500 to 50).....well i think such situations frequently come :P

When things start getting out of hand, you need to be a bit manipulative. Here you were given to achieve a task which was near impossible given the constraints and the requirements. So in this case, it doesn't hurt to be a bit innovative and lessen the limit. In this way, you would be able to complete the assignement as well as do away with the errors.

After all, this is what Engineering is all about, being innovative, manipulative and a slick guy...;)

What memory model? BC5 supports the huge model. If you split the variables among several files (as already suggested several times) and use a memory model that supports more than 64K of data, it may work. I was able to do so in BC5.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.