Go Down

Topic: Can I use the "new" C++ memory features? (Read 1 time) previous topic - next topic


Sometimes the compiler seems to be C++, and other times its like C. It knows about "class" and doesn't seem to care where variables are declared (like C++), but when I try to allocate memory dynamically:

  char *stuff = new char[10] ;

it gives me a compiler error that seems to suggest that it isn't compiling as c++, even though the file extension is cpp.

Is there a way to turn on 'new', or do I need to allocate memory the old fashioned way?



Arduino does use C++ but the AVR-GCC compiler used has some restrictions related to its use on an embedded platform.

New and delete were not supported the last time I looked at the compiler spec, but malloc and free are so you can make your own if you want, see this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230935955

with only a few k of RAM be very careful about allocating dynamic memory - its easy to run out.

Have fun!


It looks like its back to the drawing board.

Go Up