tags:

views:

219

answers:

7

Hi,

while(((long)(1000*ratio*((long)clock()-(long)t0))%100)/1000)<Data_Read_Rate);

The above line is generating the following error: "Syntax Error before < token".

Why is this error coming up?

I use MINGW32 for development(GCC compiler).

Thanks...

+8  A: 

One paren is missing on the left. This will parse:

while ((((long)(1000*ratio*((long)clock()-(long)t0))%100)/1000)<Data_Read_Rate);

Aside from the parse issue:

  • Use an editor that highlights matching parentheses :)
  • Why not calculate the time remaining until the data read rate has dropped sufficiently, and call sleep()? That's nicer on the processor.

Also, considering your use of the % operator, you may want to have the extra paren placed like so (I'm assuming ratio is not an integer), because the % operator requires integer operands:

while (((long)(1000*ratio*(((long)clock()-(long)t0))%100)/1000)<Data_Read_Rate);

(But does that make sense on a semantic level? Chop it up!)

Stephan202
I would start using a better editor...:) and thanks for the tip on using a sleep().
Manoj
No, it doesn't make sense on a semantic level. ( x % 100 ) / 1000 == 0.
DevSolar
You're right. It doesn't make any sense.
Stephan202
+3  A: 

Parenthisis are not matching. BTW, I would actually edit the code and break it up into multiple statements to make it more readable.

Naveen
+1 for concise answer without doing the homework, and also a good suggestion; more statements/lines for readability.
Adam Hawes
+4  A: 

You have too many closing parenthesis.

Plus, your logic is so long and deep that I don't care to try and figure out what the code should be. Just that vim highlights the last ) in red, meaning it's mismatched. I suggest you consider using a few intermediate variables and simplifying the logic of that statement by spreading it out into a few lines instead of one.

Chris Lutz
This is exactly what I was going to write
Andy White
A: 

You are missing one parantheses on the left side.

Aamir
A: 

You've too many Opening and closing parenthesis. If you're using visual studio, it will help you to match the opening and closing paranthesis/brace using Ctrl+'[' and Ctrl+']' key presses

Another suggestion is group and divide it into multiple lines by maintaining the readability of expressions. Also try to give space between subsequent parenthesis by to logically group the expressions.

Sarath
+2  A: 

Because the compiler gets as confused about your code as the human reader? [shudder]

Spaces and line breaks are for free, and add nicely to readability.

    while ( ( (long)( 1000 * ratio * ( (long)clock() - (long)t0 ) ) % 100 ) / 1000 ) < Data_Read_Rate );

You could do away with the (long) casts of clock() and t0, too (assuming they're both int ). Casting them before substraction won't change the result. To make the whole calculation in long, it'd be sufficient to make one of the arguments long - and the shortest way to do that is casting the literal 1000:

while ( ( ( 1000l * ratio * ( clock() - t0 ) ) % 100 ) / 1000 ) < Data_Read_Rate );

Hmmm... wait. You take something, modulo 100 (yielding a number between 0 and 99), and then divide by 1000? Your result is always 0...

Oh, and you forgot to match your parenthesis. ;-)

DevSolar
+1, for the (x%100)/1000 == 0
quinmars
+1  A: 

As mentioned previously your parentheses are mis-matched.

With expressions like this is it nearly always better to work with some interim variables to simplify the statement. However the following tips may help.

  1. Count the parentheses adding 1 for each "(" and subtracting 1 for each ")" you should always arrive at an answer of 0. A positive answer means you have an extra "(" a negative answer that you have an extra ")".
  2. Reformat the expression to make it easier to read, possibly breaking it over several lines, with each logical statement on a line.
  3. Use a syntax highlighting code-editor. This should show the mis-match for you
Steve Weet