реклама на сайте
подробности

 
 
> Использование С++ в WinAVR
ermilovd
сообщение Jan 26 2009, 10:02
Сообщение #1


Участник
*

Группа: Участник
Сообщений: 33
Регистрация: 22-01-09
Из: Пермь
Пользователь №: 43 767



Подскажите Плиз, Можно ли писать на С++ для WinAVR? Если это возможно, то выложите простенький рабочий пример использования классов с WinAVR.
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов (1 - 3)
Petka
сообщение Jan 26 2009, 10:34
Сообщение #2


Профессионал
*****

Группа: Свой
Сообщений: 1 453
Регистрация: 23-08-05
Пользователь №: 7 886



Цитата(ermilovd @ Jan 26 2009, 13:02) *
Подскажите Плиз, Можно ли писать на С++ для WinAVR? Если это возможно, то выложите простенький рабочий пример использования классов с WinAVR.

http://www.nongnu.org/avr-libc/user-manual...l#faq_cplusplus
Цитата
Can I use C++ on the AVR?
Basically yes, C++ is supported (assuming your compiler has been configured and compiled to support it, of course). Source files ending in .cc, .cpp or .C will automatically cause the compiler frontend to invoke the C++ compiler. Alternatively, the C++ compiler could be explicitly called by the name avr-c++.

However, there's currently no support for libstdc++, the standard support library needed for a complete C++ implementation. This imposes a number of restrictions on the C++ programs that can be compiled. Among them are:

* Obviously, none of the C++ related standard functions, classes, and template classes are available.

* The operators new and delete are not implemented, attempting to use them will cause the linker to complain about undefined external references. (This could perhaps be fixed.)

* Some of the supplied include files are not C++ safe, i. e. they need to be wrapped into

extern "C" { . . . }

(This could certainly be fixed, too.)

* Exceptions are not supported. Since exceptions are enabled by default in the C++ frontend, they explicitly need to be turned off using -fno-exceptions in the compiler options. Failing this, the linker will complain about an undefined external reference to __gxx_personality_sj0.

Constructors and destructors are supported though, including global ones.

When programming C++ in space- and runtime-sensitive environments like microcontrollers, extra care should be taken to avoid unwanted side effects of the C++ calling conventions like implied copy constructors that could be called upon function invocation etc. These things could easily add up into a considerable amount of time and program memory wasted. Thus, casual inspection of the generated assembler code (using the -S compiler option) seems to be warranted.
Go to the top of the page
 
+Quote Post
Сергей Борщ
сообщение Jan 26 2009, 13:48
Сообщение #3


Гуру
******

Группа: Модераторы
Сообщений: 8 455
Регистрация: 15-05-06
Из: Рига, Латвия
Пользователь №: 17 095



Цитата(ermilovd @ Jan 26 2009, 12:02) *
Подскажите Плиз, Можно ли писать на С++ для WinAVR? Если это возможно, то выложите простенький рабочий пример использования классов с WinAVR.
Можно. Вот пример. Вот тут написано, как оживить работу с динамической памятью (new, delete).


--------------------
На любой вопрос даю любой ответ
"Write code that is guaranteed to work, not code that doesn’t seem to break" (C++ FAQ)
Go to the top of the page
 
+Quote Post
Legotron
сообщение Jan 26 2009, 16:59
Сообщение #4


инопланетянин
***

Группа: Свой
Сообщений: 236
Регистрация: 24-12-06
Из: Питер
Пользователь №: 23 832



Вопрос вдогонку, кто-нибудь пользуется библиотекой AVR C++ Lib?
http://sourceforge.net/projects/avr-cpp-lib/

Какие мнения?
Мне на первый взгляд показалось немного "накрученно" smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 24th July 2025 - 19:47
Рейтинг@Mail.ru


Страница сгенерированна за 0.01357 секунд с 7
ELECTRONIX ©2004-2016