SAS/C 6.55 won't compile a 'new.h' example, why?

SAS/C 6.55 won't compile a 'new.h' example, why?

Post by Darrell Grainge » Sat, 15 Apr 1995 04:00:00



Greetings, I'm attempting to learn C++ using SAS/C 6.55. The book I have
provides the following example:

#include <iostream.h>
#include <new.h>

const Chunk = 16;
class Foo { public: int val; Foo() { val = 0; } };

char *buf = new char[ sizeof(Foo) * Chunk ];

int main(void)
{
        Foo *pb = new (buf) Foo[ Chunk ];

        if((char*)pb == buf)
                cout << "Operator new worked!: pb: " << pb
                << " buf: " << (void*)buf << endl;
        return 0;

Quote:}

When I attempt to compile this with SAS/C 6.55 I get the following
results:

====================
 Foo *pb = new (buf) Foo[ Chunk ];
                                ^
p150.cxx 11 Error 1387: No match for call to function or overloaded
operator.
                    Called with argument types:
                       ( unsigned int ,  char * )

                    None of the following matched:
                     void *operator new(unsigned int )

p150.cxx 11 Error 1607: 'operator new' must return a ( void *) not a (
signed int ).
                     void *operator new(unsigned int )

Is this because the code in the book is non-standard? Is the book using a
feature that is not portable across all compilers? Is it a typographical
error in the book? Are there features SAS/C does not support? I vaguely
remember someone mention C++ features that SAS/C did not support. Does
anyone remember what this are?

Thank you for any insight you can give me. Please reply via email as well
as posting to the newsgroup but only until May 4th. This account disappears
after that date.

Darrell

 
 
 

SAS/C 6.55 won't compile a 'new.h' example, why?

Post by Doug Walk » Tue, 18 Apr 1995 04:00:00


|> Greetings, I'm attempting to learn C++ using SAS/C 6.55. The book I have
|> provides the following example:
|>
|> #include <iostream.h>
|> #include <new.h>
|>
|> const Chunk = 16;
|> class Foo { public: int val; Foo() { val = 0; } };
|>
|> char *buf = new char[ sizeof(Foo) * Chunk ];
|>
|> int main(void)
|> {
|>   Foo *pb = new (buf) Foo[ Chunk ];

The (buf) in there is not a standard usage.  What is this syntax supposed
to do?  Use the provided memory to initialize the array into?

|> Is this because the code in the book is non-standard? Is the book using a
|> feature that is not portable across all compilers? Is it a typographical
|> error in the book? Are there features SAS/C does not support? I vaguely
|> remember someone mention C++ features that SAS/C did not support. Does
|> anyone remember what this are?

Templates and exception handling are not supported.  Also, brand-new C++
features like namespaces (added in the past 12 months or so by the ANSI C++
committee.)  However, other than these, SAS/C++ adheres to the ANSI C++
committee's working draft.

--

 *|_o_o|\\     Doug Walker<  BIX, Portal: djwalker
 *|. o.| ||                \ CompuServe: 71165,2274
  | o  |//    
  ======
Any opinions expressed are mine, not those of SAS Institute, Inc.

 
 
 

SAS/C 6.55 won't compile a 'new.h' example, why?

Post by Darrell Grainge » Wed, 19 Apr 1995 04:00:00


Thank you for the reply.



> |> Greetings, I'm attempting to learn C++ using SAS/C 6.55. The book I have
> |> provides the following example:

        [example reposted below]

Quote:> The (buf) in there is not a standard usage.  What is this syntax supposed
> to do?  Use the provided memory to initialize the array into?

According to the textbook: "The programmer may place an object allocated
from the free store at a specific address. The form of this innvocation of
operator new looks as follows:

        new (place_address) type-specifier

where place_address must be a pointer. This facility allows the programmer
to preallocate memory which at a later time will contain objects specified
by this form of operator new."

If I change the original program:

#include <iostream.h>
#include <new.h>

const Chunk = 16;
class Foo { public: int val; Foo(){ val = 0; }};

char *buf = new char[ sizeof(Foo) * Chunk ];

int main(void)
{
        Foo *pb = new (buf) Foo[ Chunk ];

        if((char*)pb == buf)    cout << "Operator new worked!: pb: "
                                << pb << " buf: " << (void*)buf << endl;
        return 0;

Quote:}

To the following:

#include <iostream.h>
#include <new.h>

const Chunk = 16;
class Foo { public: int val; Foo(){ val = 0; }};

char *buf = new char[ sizeof(Foo) * Chunk ];

int main(void)
{
        Foo *pb = (Foo *) buf;

        if((char*)pb == buf)    cout << "Operator new worked!: pb: "
                                << pb << " buf: " << (void*)buf << endl;
        return 0;

Quote:}

The code now compiles and gives me the same results as the book expects
BUT I don't believe this is really the same code.

Quote:> Templates and exception handling are not supported.  Also, brand-new C++
> features like namespaces (added in the past 12 months or so by the ANSI C++
> committee.)  However, other than these, SAS/C++ adheres to the ANSI C++
> committee's working draft.

Okay, already found out about templates. So anything with the keyword
"template", "catch" and "throw" should be avoided, right? Any other
keywords I should watch out for?

> --

>  *|_o_o|\\     Doug Walker<  BIX, Portal: djwalker
>  *|. o.| ||                \ CompuServe: 71165,2274
>   | o  |//    
>   ======
> Any opinions expressed are mine, not those of SAS Institute, Inc.

Thanks again for the help.

Darrell

 
 
 

1. SAS/C_SE 6.55 doesn't colorize 'throw'


|> Salut,
|>
|> I'm pretty sure this one has been reported already, just in case:
|> While 'try' and 'catch' are getting colorized (BTW, a very helpful feature,
|> Thanks!), 'throw' isn't. Of course, there are some other keywords in
|> the current ANSI-draft (and no one really would request something,
|> which would lead to additional work ;-), but since 'catch' and 'try'
|> are already there, I suspect 'throw' is implemented too and could be
|> easily fixed.
|>
|> Ciao,
|> Steffen Opel

I copied in a keyword list from a copy of The Annotated C++ Reference
Manual, and lo and behold, "throw" is not on the list!  Admittedly, it's
a pretty old copy...

If you know of other keywords that should be added (like "namespace", for
example), let's hear them right now.  It's trivial to add keywords, they
are just a sorted array of identifiers.  Assuming the patch isn't for-good
frozen, we just might get them in there.

--

 *|_o_o|\\     Doug Walker<  BIX, Portal: djwalker
 *|. o.| ||                \ AOL: weissblau
  | o  |//    
  ======
Any opinions expressed are mine, not those of SAS Institute, Inc.

2. Need COM advice on 16 server/ 32 client with large data transfers

3. simple K&R ANSI-C examples won't compile under SAS/C

4. Windows 2000 Pro wallpaper setting

5. DNS timeouters - "Spool them aside" rule ?

6. Why the 'New Amiga' will not be the 'Revolution'

7. REQUEST FOR INFO/experience on disks

8. Why won't GVP's FaastPrep read the rigid disk blocks it writes...

9. Can't patch SAS/C from 6.50 to 6.55

10. Ralph Babel's example 'TrapTest'

11. 1942 Monitor $300 FORSALE FORSALE''''''''''''''

12. A1000 displays '''''''''''''... when booted up