|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
multiple expression in a single For Statement |
Posted: Wed May 26, 2004 7:31 pm |
|
|
hi,
anyone in the community who can provide a sample snippet of a multiple expression for statement?
I'll appreciate any help.
Thank u. |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Wed May 26, 2004 8:34 pm |
|
|
int8 var;
int8 var1;
int8 var2;
for(var=0;var<255;var++) {
var1++;
var2++;
var1+=var2;
};
Is it all? |
|
|
Radix Guest
|
|
|
Ttelmah Guest
|
|
Posted: Thu May 27, 2004 6:57 am |
|
|
This is true for just about any 'statement'. Also, if you put a bracket round the statement group, it is the last element that is returned. So you can say (for instance)
for (i=(buff[0]=fred, buff[2]),....)
and here buff[0] will be set to the value of 'fred', while i will be set to buff[2]. This is particularly useful for generating multi-line '#define' statements, where (for instance), you can define a function to get a character from a circular buffer, like:
int8 btemp;
#define frombuff(buff,in,out,size) (btemp=out,\
out=(++out) % size, \
buff[btemp])
C is very powerful in this regard, but it can lead to very difficult to read code, and if the compiler optimisations are working properly, does not help to reduce the size of code...
Use with care.
Best Wishes |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Thu May 27, 2004 4:59 pm |
|
|
True. Once I saw some dude's code which solved the 8 queens puzzle in only one 'for' statement (and it wasn't that long either). Pure genius, but almost impossible to understand.
I wouldn't recommend doing any complicated multi-statements in CCS, as it is asking for trouble. The main rule in using CCS compiler is: stay simple. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|