🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c++
Article #175

A program that generates incorect c code

#175
From: David Sher
Date: Wed, 30 Apr 1986 00:56
49 lines
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
Technical Details
Message-ID: <17731@rochester.ARPA>
Path: arc1-ca.pugleaf.net!utzoo!linus!philabs!cmcl2!harvard!caip!seismo!rochester!sher

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!linus!philabs!cmcl2!harvard!caip!seismo!rochester!sher
From: sher@rochester.ARPA (David Sher)
Newsgroups: net.lang.c++
Subject: A program that generates incorect c code
Message-ID: <17731@rochester.ARPA>
Date: Tue, 29-Apr-86 20:56:50 EDT
Article-I.D.: rocheste.17731
Posted: Tue Apr 29 20:56:50 1986
Date-Received: Sat, 3-May-86 01:41:20 EDT
Reply-To: sher@rochester.UUCP (David Sher)
Organization: U of Rochester, CS Dept
Lines: 49
Keywords: C code , default arguments , initializers