Path: utzoo!attcan!uunet!snorkelwacker!apple!hercules!fernwood!lia!steve From: steve@lia (Stephen Williams) Newsgroups: comp.lang.c++ Subject: Re: More cfront -> ANSI C compiler problems Keywords: cfront ANSI Message-ID: <1990Jul22.234908.2820@lia> Date: 22 Jul 90 23:49:08 GMT References: <511@pete.abccam.abcl.co.uk> Reply-To: steve@lia.com (Stephen Williams) Organization: Litton/Integrated Automation, Alameda, California Lines: 136 In article <511@pete.abccam.abcl.co.uk> pete@abccam.abcl.co.uk (Peter Cockerell) writes: >It's like this. When you have a static class member, eg > >class fred { > static int jim; > ... >}; > > >it gets ouput in the ..c file as > >int _fred_jim; > >ie an uninitialized extern variable. I have encountered a similar problem while using cfront 2.0 on a SUN sparc. My code involves a class that looks like this: struct pair { short a, b; }; class foo { public: foo(); private: int x; static pair y[]; }; The code for "y" looks like: struct mangled_pair y[]; which the "C" compiler rejects, claiming "unknown size." In a sense this is true. The code that is should generate should look like: extern struct mangled_pair y[]; Whose fault is this? A shar of the complete example follows. Can anyone tell me if this problem is universal? --Steve Williams #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh Makefile <<'END_OF_Makefile' X X# -- X# What is wrong with foo.h? When foo.C is compiled, all is X# as it should be. When bar.C is compiled, cc (not CC) X# reports an error. What gives? X# Xbar: bar.o foo.o X Xfoo.o: foo.C foo.h X CC -c $(CFLAGS) foo.C X Xbar.o: bar.C foo.h X CC -c $(CFLAGS) bar.C END_OF_Makefile if test 263 -ne `wc -c foo.h <<'END_OF_foo.h' X Xstruct pair { short a, b; }; X Xclass foo { X X public: X foo(); X X private: X int x; X X // This statement generates an error if the X // actual definition of foo::y's value is X // in another file. X static pair y[]; X}; END_OF_foo.h if test 220 -ne `wc -c foo.C <<'END_OF_foo.C' X X# include "foo.h" X Xpair foo::y[] = { {1,1}, {2,2}, {3,3} }; END_OF_foo.C if test 61 -ne `wc -c bar.C <<'END_OF_bar.C' X X# include "foo.h" END_OF_bar.C if test 19 -ne `wc -c