Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > Перенос кода из С в С++


Автор: hovercraft 8.5.2013, 01:00
Вобщем в си все нормально, но вот, когда решил скомпилипровать код в С++

Код


#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)"

Почему, что компилятору не нравиться, на си всёж работало???

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

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

Автор: feodorv 8.5.2013, 01:53
Возможно, просто другие критерии обработки кода...

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


Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)