🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by "Douglas C. Schmidt" Sun, 23 Oct 1988 20:14
fatal signal on sparc
#1507
Author: "Douglas C. Schmidt"
Date: Sun, 23 Oct 1988 20:14
60 lines
1932 bytes
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.
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