2014-12-27 06:05 AM
hi every one
im trying to develop a c project in keil ,know i need to add a cpp library file to project & it shows error,i think it is because project uses c compiler & it cant compile cpp libraries,but i dosent have any suggestion to what i must do !keils error : error: #20: identifier ''class'' is undefinedlibrary consist of a lib_XX.h file (for example ) & lib_XX.cpp file & like any other libraries i include .h file in main.c (my main program file )#include ''lib_XX.h''-----libraries dosent have any problem & i used them in keil cpp project before.is there any suggestion ?best regards,Mary christmasMahmoud2014-12-27 06:36 AM
C and C++ are not the same languages! You cannot combine them together.
''class'' word does not exists in C.You have 2 options:1. Convert your cpp file to C or2. Do entire project in C++2014-12-28 01:23 AM
actually im trying to convert my last project to cpp but there is a problem too:
im using
http://en.radzio.dxp.pl/ks0108/
to initial ks0108 GLCD with stm32f103 , every thing is ok except
GLCD_Bitmapfunction
void GLCD_Bitmap( const unsigned char * bmp, unsigned char x, unsigned char y, unsigned char dx, unsigned char dy)
{
unsigned char i, j;
for(j = 0; j < dy / 8; j++)
{
GLCD_GoTo(x,y + j);
for(i = 0; i < dx; i++)
GLCD_WriteData(GLCD_ReadByteFromROMMemory(bmp++));
}
}
it draws a stored image,
GLCD_WriteDatafunction dosent have any problem because other functions used it correctly.
this function declared on ks0c file
when there is not declaration of this function on ks0h (
void GLCD_Bitmap( const unsigned char * bmp, unsigned char x, unsigned char y, unsigned char dx, unsigned char dy);
) compiler show this warning but program run correct .
warning: #223-D: function ''GLCD_Bitmap'' declared implicitlybut when i add that declaration to ks0h it show error & dosent compile:
error: #167: argument of type ''const unsigned char (*)[1024]'' is incompatible with parameter of type ''const unsigned char *''im completely mixed up,
i attached completed project if any one help me or give me a other example of ks0108 with stm32
----------------------------
http://www.edaboard.com/attachments/112673d1419752501-ks0zip
---
thanks for any help
--------------------------------
SOLVED
2015-12-29 03:20 PM
C and C++ combine very nicely - thank you very much.
I use this all day every day to migrate projects from C to a hybrid of C and C++ on the STM32.The only requirements are:1. To call C from C++ make sure you have extern ''C'' before the C function definition.2. To call C++ from C, make sure you have extern ''C'' before the C++ function definition, and it has to be a simple function (i.e. not part of a class). I'll often do this to make interface functions into the C++ from C.eg in C++class Control_Class{public: int Status; void Task(void);} Control;extern ''C'' void Control_Task(void){ Control.Task();}extern ''C'' int Control_Status(void){ return Control.Task();}In this example, Control_Task and Control_Status are both able to be called from C.In this way you can transition to C++ one source file at a time.I can't really see any disadvantages to using C++, as long as you apply the following rules:1) No new() and delete(). All classes static.2) No run time type information.3) No streams. (i.e. no << or >> operators for streaming to serial ports).If you follow these rules, the size of your binary will not increase. In fact the majority of my projects shrink between 10% and 30% because of the improved structuring that's possible.Rule 1 can be broken if you don't mind using malloc and free in your code.Rule 3 can probably be broken without much penalty in the code, but I never have.The nett result is that my C++ looks like structures with function calls. However you do gain inheritance and abstract classes / virtual functions. You don't have to make a 100% commitment to C++. Give it a try, you wont look back!