schmidt%blanche.ics.uci.edu@ORION.CF.UCI.EDU ("Douglas C. Schmidt") (10/24/88)
Hi, The following program gets a fatal signal when compiled on the Sun 4 running g++ 1.27. Furthermore, it also complains about struct state not having a method named `next.' Since this works fine under gcc on the Sun 3 I suppose there is a subtle distinction between structs in C++ and C on this point. Can someone please explain why? thanks, Doug ---------------------------------------- #include <stdio.h> struct state { struct state (*next)(struct state); }; int i = 0; struct state foo(struct state Current) { if (i < 5) { i++; } else { Current.next = NULL; } return(Current); } state_machine(struct state initstate) { struct state state = initstate; while (state.next) state = state.next(state); } main() { struct state state = { foo }; printf("i == %d\n",i); state_machine(state); printf("i == %d\n",i); } ---------------------------------------- g++ version 1.27.0 echo use .cc filename extension! use .cc filename extension! /usr/public/lib/g++/gcc-cpp+ -v -I/cd/ua/schmidt/include/ -undef -D__GNU__ -D__GNUG__ -Dsparc -Dsun -Dunix -+ state.c /tmp/cca18377.cpp GNU CPP version 1.27.0 /usr/public/lib/g++/gcc-c++ /tmp/cca18377.cpp -quiet -dumpbase state.c -fchar-charconst -version -o /tmp/cca18377.s state.c:25: structure has no method named `next' GNU C++ version 1.27.0 (sparc) compiled by GNU C version 1.28. /usr/public/g++: Program c++ got fatal signal 6.