BoostC Forum Extracts 2007

From OpenCircuits
Revision as of 07:30, 26 January 2009 by Russ hensel (talk | contribs) (New page: == Just Starting == http://forum.sourceboost.com/index.php?showtopic=3444&pid=12904&mode=threaded&start=#entry12904 A macro like MAKESHORT can initialize a variable but the compiler ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Just Starting

http://forum.sourceboost.com/index.php?showtopic=3444&pid=12904&mode=threaded&start=#entry12904


A macro like MAKESHORT can initialize a variable but the compiler does not know that and generates a warning. Is there a way to solve this without initializing the variable explicitly?


FredericG, QUOTE (FredericG @ Dec 30 2007, 06:59 PM) A macro like MAKESHORT can initialize a variable but the compiler does not know that and generates a warning. Is there a way to solve this without initializing the variable explicitly? Please provide an example of what you mean exactly.

Regards Dave



s u16_t timestamp;

t1con.TMR1ON = 0; // stop timer MAKESHORT(timestamp, tmr1l, tmr1h);

en_of_pulse = timestamp; <<==== causes warning

QUOTE It's not the macro that's the problem, but the inline assembly it uses. The compiler doesn't notice if you set a variable with inline assembly statements and warns that it's possibly uninitialized. Declaring the variable as 'volatile' gets rid of the warning, but isn't a great solution as you might miss a true 'uninitialized' case.

I am not an expert, but I think I have seen compilers that have pragma's that give hints to compiler about these things. Thanks for the workaround, I can for sure live with that solution




http://forum.sourceboost.com/index.php?showtopic=3430&pid=12890&mode=threaded&start=#entry12890


Whah, this doesn't work!

CODE typedef struct {

   char foo[11];
   bar_enum bar;

} baz_list;

baz_list baz[] = { "0123456789", quux,

                  "0123456789", quuux,
                  "0123456789", quuuux
                };


I can create a two dimensional array of strings and initialize them or a array of enums and initialize them but not an array of structs, and that sucks!!! (rhyme intended)

Any suggestions???

Jacob BoostC 6.81

This post has been edited by Jacob Christ: Dec 23 2007, 12:23 AM Interested in advertising here? Contact support@sourceboost.com




Replies twomers Dec 27 2007, 05:04 PM Post #2


Regular


Group: EstablishedMember Posts: 42 Joined: 28-November 07 From: Ireland Member No.: 3,919


A more premitive question to ask would be why:

CODE struct thing {

 char ch_1;
 char ch_2;

};

struct thing thingy = {2,2};


doesn't work.

I can't find the thread I'm thinking of but I believe you're going to have to assign the values yourself. I'd say use an inline function or something to make it look neater:

CODE struct thing {

 char ch_1;
 char ch_2;

};

inline void set_thing( struct thing &i_thing,

                      unsigned char ch_1, 
                      unsigned char ch_2 ) {
 i_thing.ch_1 = ch_1;
 i_thing.ch_2 = ch_2;

}

void main( void ){

 struct thing i_thing[3];
 set_thing( i_thing[0], 2, 3 );
 set_thing( i_thing[1], 5, 3 );
 set_thing( i_thing[2], 1, 9 );

// Or if you wish // i_thing[0].ch_1 = 2; i_thing[0].ch_2 = 3; // i_thing[1].ch_1 = 5; i_thing[1].ch_2 = 3; // i_thing[2].ch_1 = 1; i_thing[2].ch_2 = 9; }


Found the thread - http://forum.sourceboost.com/index.php?showtopic=3404