home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / g / bug / 2325 < prev    next >
Encoding:
Text File  |  1993-01-25  |  6.0 KB  |  197 lines

  1. Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!diku.dk!thansen
  2. From: thansen@diku.dk
  3. Newsgroups: gnu.g++.bug
  4. Subject: Bug: "static String a" (file scope) is not initialized
  5. Date: 25 Jan 1993 20:40:04 -0500
  6. Organization: GNUs Not Usenet
  7. Lines: 184
  8. Sender: daemon@cis.ohio-state.edu
  9. Approved: bug-g++@prep.ai.mit.edu
  10. Distribution: gnu
  11. Message-ID: <9301241245.AA00301@garm.diku.dk>
  12.  
  13. I sent this to bug-lib-g++@prep.ai.mit.edu, and Per Bothner
  14. (bothner@cygnus.com) told me it belonged here:
  15.  
  16. Bug Report.  Summary: When declaring "static String a" in file scope,
  17. "a" is not initialized. "String a" works correctly.
  18.  
  19. I am not sure if this is a bug of libg++ or gcc, please tell me if I
  20. mailed the report to the wrong place.
  21.  
  22. I am using g++ v2.3.3 and libg++ v2.3 on a SUN Sparcstation 1.  Want
  23. to declare a Variable "static String rapstd" with file scope, but it
  24. is not initialized, String::String() is not called.  If I declare it
  25. as plain "String", the constructor is called.  I have included the
  26. piece of code which contains the relevant parts.  It's very
  27. frustrating that the included piece of code *does* work correctly when
  28. I compile it without the rest of the files.  I have not been able to
  29. reproduce this error in a smaller context.  I have tried to add all
  30. the information I could think of.  Is there something I have forgotten
  31. that may influence the code?
  32.  
  33. Here's the code:  
  34.  
  35.     /* main module: rap.C */
  36.  
  37.     #include <iostream.h>
  38.     #include <String.h>
  39.     #include "etc..."
  40.  
  41.     extern "C" char * getenv( const char *name );
  42.     #define RAPLIB "/home/ask2/thansen/Propra/Source/raplib"
  43.  
  44.     typedef String fileName ;
  45.  
  46.     fileName searchpath ; // line 100 in original rap.C
  47.     fileName raperror ;
  48.     fileName raphelp ;
  49.     static fileName rapstd ; // line 116 in original rap.C
  50.     static fileName rapinit ;
  51.  
  52.     /* more declarations and functions */
  53.  
  54.     static void SetPath () {
  55.       searchpath = getenv ( "RAPLIB" ) ;
  56.       rapinit = String ( getenv ( "HOME" ) ) + "/.raprc" ;
  57.  
  58.       if ( searchpath == "" ) {
  59.     raperror = RAPLIB ;
  60.     raphelp = RAPLIB ;
  61.     rapstd = RAPLIB ;
  62.     searchpath = RAPLIB ;
  63.       } else {
  64.     raperror = searchpath ;
  65.     raphelp = searchpath ;
  66.     rapstd = searchpath ;
  67.       }
  68.       raperror += "/raperror" ;
  69.       raphelp += "/raphelp" ;
  70.       rapstd += "/rapstd" ;
  71.     }
  72.  
  73.     /* ... more functions ... */
  74.  
  75.     int main ( int argc, char* argv[] ) {
  76.       cmdDescr comd ;
  77.       Boolean error = false ;
  78.       cout << "RAP System " << RAPVersion << " " << OS
  79.         << "    (C) 1990, 1991 Universitaet Passau\n\n" ;
  80.       SetPath () ;
  81.       /* any line to check the values of rapstd and rapinit, e.g.
  82.        * cout << "rapstd: " << rapstd << "\nrapinit: " << rapinit
  83.        *      << "\nraphelp: " << raphelp << "\n" ;
  84.        */
  85.     }
  86.  
  87.     /* in the header files */
  88.  
  89.     #define PATCHLEVEL "0"
  90.     #define RAPVersion ( String ( "0.0." ) + PATCHLEVEL )
  91.     #define OS "for SunOS"
  92.  
  93.     class Boolean {
  94.     private:
  95.       int b ;
  96.     public:
  97.       Boolean ( int i = 0 ) ;
  98.       operator int () const ;
  99.     } ;
  100.  
  101.     enum command { helpCmd, nopCmd, /* ..., */ exitCmd } ;
  102.  
  103.     typedef optDescr* optPtr ;
  104.     typedef valDescr* valPtr ;
  105.  
  106.     struct cmdDescr {    
  107.       command c ;
  108.       optPtr o ;
  109.       valPtr p ;
  110.     } ;
  111.  
  112. The whole program executes correctly if I remove the two "static"s
  113. before "rapstd" and "rapinit".  Here's what gdb gives for the version
  114. with static:
  115.  
  116.     (gdb) break SetPath
  117.     Breakpoint 1 at 0x54834: file ./rap.C, line 133.
  118.     (gdb) run
  119.     Starting program: /net/ask/home/ask2/thansen/Propra/Source/rap 
  120.     RAP System 0.0.0 for SunOS    (C) 1990, 1991 Universitaet Passau
  121.  
  122.  
  123.     Breakpoint 1, SetPath () at ./rap.C:133
  124.     133       searchpath = getenv ( "RAPLIB" ) ;
  125.     (gdb) print rapstd
  126.     $1 = {rep = 0xad878}
  127.     (gdb) print &_nilStrRep
  128.     $2 = (StrRep *) 0x82528
  129.     (gdb) print *rapstd.rep 
  130.     $3 = {len = 10, sz = 55800, s = {"\000"}}
  131.     (gdb) print raperror
  132.     $4 = {rep = 0x82528}
  133.     (gdb) print rapstd.OK()
  134.     String Error: invariant failure
  135.  
  136.     Program received signal 6, Abort
  137.     0xf775eb20 in kill ()
  138.     The program being debugged stopped while in a function called from GDB.
  139.     The expression which contained the function call has been discarded.
  140.     Unable to restore previously selected frame.
  141.  
  142. It looked like the constructor String::String() was not called for
  143. "rapstd", so I tried this:
  144.  
  145.     (gdb) break rap.C:100
  146.     Breakpoint 3 at 0x58c64: file ./rap.C, line 100.
  147.     (gdb) break rap.C:116
  148.     Breakpoint 4 at 0x58c94: file ./rap.C, line 116.
  149.     (gdb) run
  150.     The program being debugged has been started already.
  151.     Start it from the beginning? (y or n) y
  152.     Starting program: /net/ask/home/ask2/thansen/Propra/Source/rap 
  153.  
  154.     Breakpoint 3, _GLOBAL_$I$searchpath () at ./rap.C:100
  155.     100       fileName /*@THH*/ searchpath ;
  156.     (gdb) print &searchpath
  157.     $3 = (struct String *) 0x824d4
  158.     (gdb) s
  159.     String::String (this=0x824d4) at ./String.h:465
  160.     ./String.h:465: No such file or directory.
  161.     (gdb) cont
  162.     Continuing.
  163.  
  164.     Breakpoint 4, _GLOBAL_$I$searchpath () at ./rap.C:117
  165.     117       static fileName /*@THH*/ rapinit ;
  166.     (gdb) print &rapinit
  167.     $4 = (struct String *) 0x82518
  168.     (gdb) s    
  169.     String::String (this=0xaa210) at ./String.h:465
  170.     ./String.h:465: No such file or directory.
  171.     (gdb) n
  172.     _GLOBAL_$I$searchpath () at ./rap.C:122
  173.     122       static void    PutL ( flist*, fileName /*@THH*/ ) ;
  174.     (gdb) print rapinit
  175.     $5 = {rep = 0x0}
  176.     (gdb) print searchpath
  177.     $6 = {rep = 0x82528}
  178.  
  179. >From file String.h, line 464-465:
  180.     inline String::String() 
  181.       : rep(&_nilStrRep) {}
  182.  
  183. Shouldn't "rapinit" be "{rep = 0x82528}"?  
  184.  
  185. That's all useful information I can think of.  If I have forgotten any
  186. useful information, please tell me.
  187.  
  188. Best regards,
  189.     Thorbjoern Hansen
  190.  
  191. -- 
  192. Thorbjoern Hansen, thansen@diku.dk, hansen@forwiss.uni-passau.de
  193.   "Mystics are all a bit funny in the head anyway, which is why the
  194.   church locks them all up in mental hospitals and euphemistically calls
  195.   these institutions monasteries." -- Shea & Wilson, "Illuminatus!"
  196.  
  197.