[net.lang.c++] A program that generates incorect c code

sher@rochester.ARPA (David Sher) (04/30/86)

I have an example of what I believe is correct c++ code acording to
the book but which causes c++ to generate incorrect c code.
The basis of this is that it is correct to use the notation
char x[2] = { '1' , '2' } according to the book to initialize
arrays anywhere.  Actually if you use this notation on stack
variables the compiler returns a sorry not implemented message.
However if one uses it for default arguments c++ generates 
incorrect c code causing cc to complain.  I suspect that the correct
behavior is to generate another sorry not implemented message for this
too.  The code that causes this behavior is at the bottom of this
message.

By the way the problem from my previous posting seemed to be that
enums within classes have obscure scope and so enclosing an enum
type within a class is a very dangerous thing to do with the current
implementation of c++.

-David Sher
sher@rochester
seismo!rochester!sher

#include <stream.h>

void
foo ( char arg[2] = { '[' , ']' } );

void
foo ( char arg[2] )
    {
    char * string = new char [3] ;
    string[0] = arg[0];
    string[1] = arg[1];
    string[2] = '\0';
    cout << string << "\n";
    }

char x[2] = { 'H' , 'i' };

void
main ()
    {
    foo ( );
    foo ( x );
    }

-- 
-David Sher
sher@rochester
seismo!rochester!sher