[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[oc] Commas? Concurrent execution in standard C?



Jim,

firstly you are wrong mate, secondly thanks.

> Note the use of comma "," instead of semicolon ";". In C/C++ statements
> occur in the logical order that is equivalent to the order in which they are
> written. 

Completely wrong there. A comma denotes a list in C/C++ for example

enum {one, two, buckle, my, shoe}		// List of identifiers to be enumerated
printf("Hi Jim %d%c%l", int, char, long)	// List of parameters to be passed to func

A semi-colon denotes the end of a statement and I suppose you could surmise
it also infers a sequential operation of those statements. There is no guarantees
in C/C++ as to how the assignments in a list will be executed although most
people assume its in "top down" fashion. Quite a few compilers work in a 
"bottom up" fashion as its easier, I'll explain for anybody interested.
In the following typical C statement:

	A = B + C ;

a bottom up compiler would see the semi, then would see the C + B, it would
code a function to evaluate this addition. Then it would see = A so it would
assign the value from its previous function to the variable A. A "top down"
compiler would see the A first, not knowing if it was a function call A() or
an assignment statement yet it would (in theory) push A onto some sort of stack.
Then it would see the assignment operator (in C/C++ == means equals, = is 
assign a value) so now it knows that its an assignment so it looks at up to the
semi-colon. Now it codes that C must be added to B and pulls A off its stack in
order so that it knows where to put it. Don't panic, I can write C a 100 times
easier than I can explain what the hell its actually doing. Hopefully now those
who wish to can understand the difference in compiler styles. So if you have
the following commands

int x = 10 ;
printf ("x = %d, %d", x++, (int) x == 10) ;

do you get "x=10, 1" (1 is true), or "x=10, 0" (0 is false) ? I personally
wouldn't guarantee one or the other as its compiler dependent.

> When using semicolon you specify a logical order of sequence of
> operation. When using comma you specify that the operations _logically_
> appear to occur at the same time but can be ordered arbitrarily.

Second part now, thanks I was thinking the other day whilst working on the
C++ to Verilog translator about the sequential alterations I was going to do to
"vanilla C" in order to support the sequential nature that implementation in
FPGAs could allow the C++ program. Handel-C uses 

par
{
	function1() ;
	function2() ;
}

to permit you to run the two functions in parallel. So now after your slightly
wrong assumption I'm thinking about using commas at the end of statements instead
of semi-colons to signify the instructions are in a kind of "parallel list" rather
than sequential statements e.g.

function1(),
function2(),
function3() ;

So now all 3 functions will run concurrently when compiled with my program. Still
debating this with myself (just me, myself and I so no deadlocked votes) which to
use. Anybody want to vote for either out there? Let the public decide time, all
C programmers which do you prefer?

Paul

--
To unsubscribe from cores mailing list please visit http://www.opencores.org/mailinglists.shtml