Модераторы: Daevaorn
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Перенос кода из С в С++ 
V
    Опции темы
hovercraft
Дата 8.5.2013, 01:00 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 12
Регистрация: 9.8.2012

Репутация: нет
Всего: нет



Вобщем в си все нормально, но вот, когда решил скомпилипровать код в С++

Код


#define P_EP(n) ((USB_EP_EVENT & (1 << (n))) ? USB_EndPoint##n : NULL)

/* USB Endpoint Events Callback Pointers */
void (* const USB_P_EP[16]) (U32 event) = {
  P_EP(0),
  P_EP(1),
  P_EP(2),
  P_EP(3),
  P_EP(4),
  P_EP(5),
  P_EP(6),
  P_EP(7),
  P_EP(8),
  P_EP(9),
  P_EP(10),
  P_EP(11),
  P_EP(12),
  P_EP(13),
  P_EP(14),
  P_EP(15),
};

ахтунг ааа
Код

usbuser.c(168): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(168): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(169): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(169): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(170): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(170): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(171): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(171): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(172): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(172): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(173): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(173): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(174): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(174): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(175): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(175): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(176): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(176): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(177): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(177): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(178): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(178): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(179): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(179): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(180): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(180): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(181): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(181): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(182): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(182): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"
usbuser.c(183): warning:  #42-D: operand types are incompatible ("void (*)(U32)" and "void *")
usbuser.c(183): error:  #144: a value of type "void *" cannot be used to initialize an entity of type "void (*const)(U32)"

Почему, что компилятору не нравиться, на си всёж работало???
PM   Вверх
baldina
Дата 8.5.2013, 01:45 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
****


Профиль
Группа: Завсегдатай
Сообщений: 3433
Регистрация: 5.12.2007
Где: Москва

Репутация: 32
Всего: 101



видимо USB_EndPoint0..15 определены как void указатели (не на функцию). в С++ типизация строже, вот и ругается.
можно преобразовать к целому типу достаточной разрядности
Код

#define P_EP(n) long((USB_EP_EVENT & (1 << (n))) ? USB_EndPoint##n : NULL)

PM MAIL   Вверх
feodorv
Дата 8.5.2013, 01:53 (ссылка) |   (голосов:1) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
****


Профиль
Группа: Комодератор
Сообщений: 2214
Регистрация: 30.7.2011

Репутация: 11
Всего: 45



Возможно, просто другие критерии обработки кода...

Есть мысль, что здесь NULL определён как (void *) 0, а не как просто 0. Попробуйте:
Цитата(hovercraft @  8.5.2013,  02:00 Найти цитируемый пост)
#define P_EP(n) ((USB_EP_EVENT & (1 << (n))) ? USB_EndPoint##n : 0)




--------------------
Напильник, велосипед, грабли и костыли - основные инструменты программиста...
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "С++:Общие вопросы"
Earnest Daevaorn

Добро пожаловать!

  • Черновик стандарта C++ (за октябрь 2005) можно скачать с этого сайта. Прямая ссылка на файл черновика(4.4мб).
  • Черновик стандарта C (за сентябрь 2005) можно скачать с этого сайта. Прямая ссылка на файл черновика (3.4мб).
  • Прежде чем задать вопрос, прочтите это и/или это!
  • Здесь хранится весь мировой запас ссылок на документы, связанные с C++ :)
  • Не брезгуйте пользоваться тегами [code=cpp][/code].
  • Пожалуйста, не просите написать за вас программы в этом разделе - для этого существует "Центр Помощи".
  • C++ FAQ

Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, Earnest Daevaorn

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | C/C++: Общие вопросы | Следующая тема »


 




[ Время генерации скрипта: 0.0933 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.