🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by "Douglas C. Schmidt" Sun, 27 Nov 1988 03:00
g++ ignores static const's in private class section
#1545
Author: "Douglas C. Schmidt"
Date: Sun, 27 Nov 1988 03:00
80 lines
2550 bytes
Hi,

  I believe the following is valid C++ code.  cfront 1.2.1 accepts and
executes it correctly.  G++ 1.27 produces the following error message:

----------------------------------------
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 -+ reverse_video.c
/tmp/cca01184.cpp

GNU CPP version 1.27.0
 /usr/public/lib/g++/gcc-c++ /tmp/cca01184.cpp -quiet -dumpbase
reverse_video.c -finline-functions -fmemoize-lookups -fsave-memoized
-fchar-charconst -version -o /tmp/cca01184.s

At top level:
reverse_video.c:19: undeclared variable `MAX_SIZE' (first use here)
GNU C++ version 1.27.0 (sparc) compiled by GNU C version 1.28.
----------------------------------------

However, I believe this usage of static constants is allowed.

Here's the code:

----------------------------------------
#include <stream.h>

int   tgetent( char *bp, char *name );
char *tgetstr( char *id, char **area );
int   tputs( char *cp, int affcnt, int (*outc)( int ) );
char *getlogin ( void );

int putchr( int i ) {
   return ( putchar(i) );
}

class Inverse {

private:

   // g++ seems to ignore this static constant declaration
   static const int MAX_SIZE = 1024;
   char   sbuf [ MAX_SIZE ];
   char  *sp;
   char   bp [ MAX_SIZE ];
   char  *so_start;
   char  *so_end;

public:

   Inverse ( void ): sp ( sbuf ) {
      if ( tgetent ( bp, getenv ( "TERM" ) ) != 1 ) {
         cerr << "error: termcap read failure\n",exit ( 1 );
      }
      so_start = tgetstr ( "so", &sp );
      so_end   = tgetstr ( "se", &sp );
   }

   Inverse& operator () ( char *Buf ) {
      tputs ( so_start, 1, putchr );
      cout << Buf;
      tputs ( so_end, 1, putchr );
      return ( *this );
   }

   friend ostream& operator << ( ostream& s, Inverse &i ) { // dummy function
      ;
   }

};

main ( int argc,char *argv[ ] ) {
   Inverse V;
   
   cout << "hello, you are " << V ( getlogin ( ) ) << "\n";
}
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