🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by James Clark Thu, 11 May 1989 18:06
virtual base classes
#1988
Author: James Clark
Date: Thu, 11 May 1989 18:06
66 lines
2228 bytes
I'm having problems with virtual base classes:

Script started on Thu May 11 18:53:46 1989
jclark% cat test.c
#include <stdio.h>

struct A {
  int n;
  void set(int);
  void print();
};

void A::set(int i)
{
  n = i;
}

void A::print()
{
  fprintf(stderr, "%d\n", n);
}

struct B : virtual A {
};


main()
{
  B *p = new B;
  p->set(5);
  p->print();
  fprintf(stderr, "p->n = %d\n", p->n);
}
jclark% make test
/u/local/g++/g++ -B/u/local/g++/ -g -v -I.   -sun4 -o test test.c 
g++ version 1.35.0-
 /usr/local/lib/gcc-cpp -+ -v -I. -undef -D__GNU__ -D__GNUG__ -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ test.c /tmp/cca25650.cpp
GNU CPP version 1.35
 /u/local/g++/cc1plus /tmp/cca25650.cpp -quiet -dumpbase test.c -noreg -version -G -o /tmp/cca25650.s
GNU C++ version 1.35.0- (sparc) compiled by GNU C version 1.35.
 as /tmp/cca25650.s -o test.o
 /u/local/g++/ld++ -o test -C -C /u/local/g++/crt0+.o test.o -lg++ /usr/local/lib/gcc-gnulib -lg -lc
/u/local/g++/g++: unrecognized option `-sun4'
jclark% test
Segmentation fault (core dumped)
jclark% gdb test core
GDB 3.1, Copyright (C) 1988 Free Software Foundation, Inc.
There is ABSOLUTELY NO WARRANTY for GDB; type "info warranty" for details.
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "info copying" to see the conditions.
Reading symbol data from /u/jjc/test/test...done.
Core file is from "test".
Program terminated with signal 11, Segmentation fault.
Type "help" for a list of commands.
(gdb) where
#0  0x2120 in set_PSA_SI ($this=(struct A *) 0x0, i=5) (test.c line 11)
#1  0x2198 in main () (test.c line 26)
(gdb) quit
jclark% exit
jclark% 
script done on Thu May 11 18:54:21 1989

If I've understood virtual base classes, this ought to have worked.

James Clark
jjc@jclark.uucp
virtual base classes
#1989
Author: Michael Tiemann
Date: Fri, 12 May 1989 10:48
40 lines
1063 bytes
   I'm having problems with virtual base classes:
   
   Script started on Thu May 11 18:53:46 1989
   jclark% cat test.c
   #include <stdio.h>
   
   struct A {
     int n;
     void set(int);
     void print();
   };
   
   void A::set(int i)
   {
     n = i;
   }
   
   void A::print()
   {
     fprintf(stderr, "%d\n", n);
   }
   
   struct B : virtual A {
   };
   
   
   main()
   {
     B *p = new B;
     p->set(5);
     p->print();
     fprintf(stderr, "p->n = %d\n", p->n);
   }

Here is what I get with this morning's compiler:

yahi% a.out
5
p->n = 5
Re: virtual base classes
#2068
Author: ekrell
Date: Sun, 04 Jun 1989 22:13
6 lines
516 bytes
With a pre-release cfront 2.0, I get:

5
p->n = 5

so it looks like you found a g++ bug.
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