🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by "Douglas C. Schmidt" Sun, 01 Jan 1989 21:36
Hacked patch for array subscripting
#1588
Author: "Douglas C. Schmidt"
Date: Sun, 01 Jan 1989 21:36
61 lines
2527 bytes
Hi,

   g++ 1.32 does not correctly handle the communtativity of array and
pointer indexing, i.e., A [ 0 ] == 0 [ A ]; I believe the following
patch fixes this temporarily.  I've tested it a little, but I don't
know if it breaks something else.

   Here's an example of what *didn't* compile before, and now does:

----------------------------------------
main ( ) {
   typedef int VEC [ 20 ];
   typedef VEC ( *PTA );

   VEC a [ 10 ];
   PTA ap = a;
   
   0 [ ap ] [ 0 ] = 10000; // yikes, this is valid!
   printf ( " * 0 [ ap ] = %d\n", * 0 [ ap ] ); // so's this!
}
----------------------------------------

Here are the original diagnostics:

----------------------------------------
g++ version 1.32.0
 /usr/public/lib/g++/gcc-cpp -+ -v -I/cd/ua/schmidt/include/ -undef
-D__GNU__ -D__GNUG__ -Dsparc -Dsun -Dunix test.c /tmp/cca06819.cpp
GNU CPP version 1.32
 /usr/public/lib/g++/gcc-c++ /tmp/cca06819.cpp -quiet -dumpbase test.c
-fstrength-reduce -finline-functions -fmemoize-lookups -fsave-memoized
-fchar-charconst -version -o /tmp/cca06819.s
GNU C++ version 1.32.0 (sparc) compiled by GNU C version 1.31.
In function int main ():
test.c:8: [] applied to non-pointer type
test.c:8: [] applied to non-pointer type
test.c:8: invalid lvalue in assignment
test.c:9: [] applied to non-pointer type
test.c:9: invalid type argument of `unary *'
----------------------------------------

This now compiles and executes correctly with the following patch.

Doug

----------------------------------------
*** /usr/src/uci/usr/public/src-g++/cplus-parse.y	Sat Dec 31 13:58:05 1988
--- cplus-parse.y	Sun Jan  1 12:48:16 1989
***************
*** 672,677 ****
--- 672,680 ----
  			else if (TREE_CODE(type) == POINTER_TYPE
  				 || TREE_CODE(type) == ARRAY_TYPE)
  			  $$ = build_array_ref ($1, $3);
+          else if (TREE_CODE (TREE_TYPE ($3)) == POINTER_TYPE
+              || TREE_CODE (TREE_TYPE ($3)) == ARRAY_TYPE)
+ 			  $$ = build_array_ref ($1, $3); 
  			else
  			  error("[] applied to non-pointer type");
  		      }
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