Thread View: net.lang.c++
1 messages
1 total messages
Started by David Sher
Wed, 30 Apr 1986 00:56
A program that generates incorect c code
Author: David Sher
Date: Wed, 30 Apr 1986 00:56
Date: Wed, 30 Apr 1986 00:56
49 lines
1911 bytes
1911 bytes
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
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