🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1588

Hacked patch for array subscripting

#1588
From: "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");
  		      }
Technical Details
Message-ID: <8901011343.aa03759@PARIS.ICS.UCI.EDU>
Path: arc1-ca.pugleaf.net!utzoo!telly!ddsw1!lll-winken!uunet!tut.cis.ohio-state.edu!PARIS.ICS.UCI.EDU!schmidt%siam.ics.uci.edu

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!ddsw1!lll-winken!uunet!tut.cis.ohio-state.edu!PARIS.ICS.UCI.EDU!schmidt%siam.ics.uci.edu
From: schmidt%siam.ics.uci.edu@PARIS.ICS.UCI.EDU ("Douglas C. Schmidt")
Newsgroups: gnu.g++.bug
Subject: Hacked patch for array subscripting
Message-ID: <8901011343.aa03759@PARIS.ICS.UCI.EDU>
Date: 1 Jan 89 21:36:01 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 61