Hi Olly,

On Tue, Feb 15, 2000 at 03:22:49AM +0000, Olly Betts wrote:
> In message <[EMAIL PROTECTED]>, Ossama Othman writes:
> >Something like the following should be a good smoke test:
> >
> >  class Foo
> >  {
> >   public:
> >     Foo (void) : bar_ (0) { }
> >     virtual ~Foo (void) { }
> >     virtual int bar (void) { return this->bar_; }
> >   private:
> >     int bar_;
> >  };
> >
> >  int main (int, char *[])
> >  {
> >   Foo fnord;
> >   int a = fnord.bar ();
> >   return a;
> >  }
> 
> Just noticed a problem with this.  If you compile it with:
> 
> gcc -o test test.cc

Right, I noticed that too.  Hopefully `gcc' won't be part of the
C++ compiler search list, unless there is good reason for it.

> You get a working executable called test.  But in gcc won't link this
> C++ program:
> 
> #include <iostream>

Note that <iostream> still isn't supported by some C++ compilers.
<iostream.h> would have to be used.

> int main() { cout << "hello world\n"; return 0; }
> 
> This is what happens (gcc 2.95.2 on Linux):
> 
> $ gcc -o a.out test2.cc
> /tmp/ccx2KlXv.o: In function main':
> /tmp/ccx2KlXv.o(.text+0xf): undefined reference to cout'
> /tmp/ccx2KlXv.o(.text+0x14): undefined reference to ostream::operator<<(char const 
>*)'
> collect2: ld returned 1 exit status
> 
> Both programs compile and run fine when using g++ in place of gcc.
> 
> So it looks like the test program probably ought to use at least one
> library function to make sure that the right libraries are getting
> linked in.
> 
> Thoughts as to a good candidate?

I'm a bit leary about using library functions, particularly those from
C++ libraries for several reasons:

1. A C++ library may not be installed (believe it or not), or someone
could even supply the following for g++ (for example):

        CXX=c++ CXXFLAGS=-nostdlib ./configure

in which case, `libstdc++' wouldn't be linked, and similary for Sun
C++:

        CXX=CC CXXFLAGS=-library=no%iostream,no%Cstd ./configure

Admittedly, these are odd configurations but they are certainly valid
configurations.

I don't think we can assume everyone uses the standard C++ library, or
even has it installed.

2. Some standard C++ libraries may actually place functions/classes in
the "std" namespace.  For example, the following may potentially be
required for some platforms:

        int main() { std::cout << "hello world\n"; return 0; }

This is problem for C++ compilers/libraries that don't provide a "std"
namespace.  The following is also problematic:

        using namespace std;
        int main() { cout << "hello world\n"; return 0; }

Since not all C++ compilers support the "using" keyword, or even
support namespaces via the "namespace" keyword.


It is for these reasons why I didn't include any library functions in
the simple test I posted.  My goal for the test was to use C++
features that all C++ compilers should support (base member
initialization, virtual functions and a "this" pointer), that didn't
rely on anything external, such as a library. Unfortunately, I can't
think of any better tests or ideas either; at least not at the
moment. :-)

Thoughts?  Disagreements?

-Ossama
-- 
Ossama Othman <[EMAIL PROTECTED]>
Distributed Object Computing Laboratory, Univ. of California at Irvine
1024D/F7A394A8 - 84ED AA0B 1203 99E4 1068  70E6 5EB7 5E71 F7A3 94A8

Reply via email to