david
david

Reputation: 1

error: array bound forbidden after parenthesized type-id

I'm trying to compile a program written in the year 2001 in C++. When I run the setup script (ie ./setup) in the terminal, I get the error shown below. I have searched for a solution but the idea I get is that this type of error is produced by later versions of gcc ie versions 4 and above. How can I edit the code where the compiler shows errors so that it runs without the error.

david@david-Satellite-C55-B:~$ cd Desktop/WebTraff/WebTraff && ./setup
Making executables in root directory

make: Nothing to be done for 'all'.

Making ProWGen

g++ -c -g stream.cc
stream.cc: In member function ‘unsigned int* RequestStream::GeneratePopularities()’:
stream.cc:104:39: error: array bound forbidden after parenthesized type-id
   if ((popularity = new (unsigned int)[noofDistinctDocs]) ==  NULL) 
                                       ^
stream.cc:104:39: note: try removing the parentheses around the type-id
stream.cc: In member function ‘unsigned int* RequestStream::GenerateFileSizes()’:
stream.cc:173:49: error: array bound forbidden after parenthesized type-id
     unsigned int *filesizes = new (unsigned int)[noofDistinctDocs];
                                                 ^
stream.cc:173:49: note: try removing the parentheses around the type-id
stream.cc: In member function ‘void RequestStream::GenerateUniqueDocs(Node*, int, Node*, int)’:
stream.cc:378:28: error: array bound forbidden after parenthesized type-id
  uniqueDoc = new (Request*)[noofDistinctDocs];
                            ^
stream.cc:378:28: note: try removing the parentheses around the type-id
Makefile:11: recipe for target 'stream.o' failed
make: *** [stream.o] Error 1
cp: cannot stat 'ProWGen': No such file or directory

Making CacheDriver

g++ -c CacheDriver.cc
g++ -c lru.cc
lru.cc: In constructor ‘Lru::Lru(unsigned int)’:
lru.cc:21:36: error: array bound forbidden after parenthesized type-id
   if ( (hash_table = new (LruNode*)[MAX_SIZE]) == NULL)
                                    ^
lru.cc:21:36: note: try removing the parentheses around the type-id
lru.cc:23:61: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
      ErrorMessage("Not enough memory to allocate hash table");
                                                             ^
lru.cc: In member function ‘LruNode* Lru::get_new_node(unsigned int, unsigned int)’:
lru.cc:143:59: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
   ErrorMessage("Cannot allocate more memory for new nodes");
                                                           ^
lru.cc: In member function ‘void Lru::found_update(LruNode*)’:
lru.cc:270:66: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
  if((loc != head)&&(succloc == NULL)) ErrorMessage("\nright here");
                                                                  ^
Makefile:8: recipe for target 'CacheDriver' failed
make: *** [CacheDriver] Error 1
cp: cannot stat 'CacheDriver': No such file or directory

Making popularity

gcc -o popularity main.o getch.o gettoken.o hash.o -lm 

Making lrustack and freqsize

make: Nothing to be done for 'all'.

Upvotes: 0

Views: 2324

Answers (1)

M.M
M.M

Reputation: 141638

new (unsigned int)[noofDistinctDocs] is a syntax error. I'm guessing you meant:

new unsigned int[noofDistinctDocs]

which allocates an array of unsigned int. There are the same sort of error later in the code too.

Upvotes: 2

Related Questions