BoostC Forum Extracts 2007
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
http://forum.sourceboost.com/index.php?showtopic=3440&pid=12882&mode=threaded&start=#entry12882
Dec 28 2007, 12:28 PM
Post #1
Newbrie
Group: EstablishedMember
Posts: 12
Joined: 27-December 07
Member No.: 3,967
Hi,
I'm a Windows C++ programmer, used to using doubles, just because why not and making huge classes.
So this pic stuff is pretty different to say the least.
So far so good, still trying to get an interrupt to work, but it's obviously me, not the compiler, I did a search, popular topic!
Anyway about the compiler, BoostC, I like it better that Hitec, it seems to be a little C++ like in some ways( thats good :-).
Question 1; Function prototypes, It looks like they are allowed, but not required nor enforced?
If I call delay_ms(1000 ); I get no warnings.
Is there a way to make it more strict? I don't see a warning level setting anywhere, maybe I missed it?
Interrupts;
if I don't put the interrupt function in my code, is there a default handler?
Can I put the interrupt handler in any file? ( seems weird not to have to 'hook it up')
Global variables vs volatile;
If I declare a variable in a header file, and wish to use it in both a main thread function and an interrupt handler, do I really need to declare it volatile?
Why would the compiler make a copy of it for the interrupt??
Thanks Keith Interested in advertising here? Contact support@sourceboost.com
Replies Reynard Dec 29 2007, 06:42 AM Post #2
Enthusiast
Group: EstablishedMember
Posts: 186
Joined: 24-October 07
From: Scotland
Member No.: 3,861
Hi Keith,
This compiler is a bit different than MSC.
Prototypes are required if you do a forward reference to a function. If you are in the habit of using them, then always use them. I do.
If you go to Settings - Options and enable All warnings the compiler will warn you if you exceed 255 for a delay.
There is no default interrupt handler that I can see. Keep GIE = 0 if you don't want you program to go into the woods.
If I was sharing a variable with main and interrupt, I would probably make it volatile. It all depends on how your main code is written and how many times the variable is used in main. The compiler may retain the variable value between uses and the interrupt may change its value between uses. You could always devise a semaphore type system.
Hitec is a very good compiler if you can afford it. Other low cost ones are MikroC and Wiz-C.
Cheers
Reynard
http://forum.sourceboost.com/index.php?showtopic=3427&pid=12856&mode=threaded&start=#entry12856
I had some code that suddenly got bigger and slower and all I'd done was change the size of an array, though no variables ended up placed anywhere but bank 0.
I tracked it down to some uses of porta which were getting both RP0 and RP1 cleared each time before it was used. Even though in some cases, the flow of control made it obviously unnecessary, the initial clear was necessary due to accessing trisa a while back in the call tree. What was particularly bad was the bank switching instructions were inside a loop.
The simplest solution was to force a local variable that is set before the loop into bank 0 only RAM so the bank switching is done to set this variable. The extra unwanted bank switching then went away. All other access in the loop turned out to be in locations which are shared between banks.
Another solution was to force the array I'd changed out into bank 1 and yet another was to use a global variable for the bit count which just happened to be in bank 0 only RAM.
Here is the offending function. It makes no difference whether the C or assembly version is used:
read more on the thread for possible optimizations involving bank switching