From: Philipp K. K. <pk...@sp...> - 2006-04-24 16:09:55
|
Richard Erlacher wrote: > Isn't that like using a '747 to commute to work? > > I've always been persuaded that, while 'C' is a general-puprose > language, C++ is intended for big projects, with dozens of teams of > hundreds of programmers, and hundreds of managers, with work-product in > the tens of millions of lines. I don't see a PIC16 or whatever being > able to accomodate that sort o thing. Programming "in the large" > doesn't happen much in the microcontroller world. > > regards, > > Richard Erlacher I had had to choose between C++ support and seeing the problems I mentioned fixed, I'd prefer the problems fixed. But I don't hink C++ is useless for embedded applications: I sometimes see the scenario of a data structure and some functions using it, which are closely tied to the struct, in projects for which I use sdcc. An example is the header file below. Using a class and member functions would be the natural choice (and an inline function instead of the macro). The resulting code would be the same, so there wouldn't be any speed or code size problem. #ifndef CVU_GRAPHICS_H #define CVU_GRAPHICS 1 #include <stdint.h> #include "cv_graphics.h" struct cvu_sprite { uint8_t y; uint8_t x; uint8_t name; uint8_t tag; }; // Write sprite to display memory. Use the location of the sprite table as base. number should be in [0, 31]. //extern void cvu_set_sprite(const cv_vmemp base, const unsigned int number, const struct cvu_sprite *sprite); #define cvu_set_sprite(base, number, sprite) cv_memtovmemcpy((base) + (number) * 0x4, (sprite), 4) // Todo: is cvu_get_sprite needed? // Set the x coordinate of the sprite's upper left corner. x will be clamped to [-32, 255] extern void cvu_set_sprite_x(struct cvu_sprite *sprite, int x); extern int cvu_get_sprite_x(const struct cvu_sprite *sprite); // Set the y coordinate of the sprite's upper left corner. y will be clamped to [-32, 207] extern void cvu_set_sprite_y(struct cvu_sprite *sprite, int y); extern int cvu_get_sprite_y(const struct cvu_sprite *sprite); // Set the sprite's color. //extern void cvu_set_sprite_color(struct cvu_sprite *sprite, enum cv_color color); #define cvu_set_sprite_color(sprite, color) (sprite)->tag = ((sprite)->tag & 0x80) | (color); extern enum cv_color cvu_get_sprite_color(struct cvu_sprite *sprite); #endif |