Unix Programming - Invalid Operator to binary *

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2006 > Invalid Operator to binary *





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Invalid Operator to binary *
Mihir

2006-07-27, 1:27 pm

I am getting this error for both "*" and "/"..

Here is the code from where it is coming...
----------------
#ifdef LINUX_OS
if (_TICKSPERSEC < 1000)
time_elapsed = (time_elapsed * (1000 / _TICKSPERSEC));
else
time_elapsed = (time_elapsed /(_TICKSPERSEC / 1000));
#else
#if (_TICKSPERSEC < 1000)
time_elapsed = (time_elapsed * (1000 / _TICKSPERSEC));
#else
time_elapsed = (time_elapsed /(_TICKSPERSEC / 1000));
#endif
#endif
----------------
_TICKSPERSEC is defined as "sysconf(_SC_CLK_TCK)" and time_elapsed is
defined as "unsigned long"

I also try modefying it to "*= " and "/="... but it still is giving me
same error.....

Paul D. Smith

2006-07-27, 1:27 pm

%% "Mihir" <patel.ma@gmail.com> writes:

m> I am getting this error for both "*" and "/"..

m> #if (_TICKSPERSEC < 1000)

m> _TICKSPERSEC is defined as "sysconf(_SC_CLK_TCK)"

The preprocessor needs to evaluate its arguments at compile time, so
all parts of an expression must be constant. sysconf() is a runtime
function call, so you can't use it in a preprocessor statement.

--
-------------------------------------------------------------------------------
Paul D. Smith <psmith@nortel.com> HASMAT--HA Software Mthds & Tools
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
These are my opinions--Nortel takes no responsibility for them.
Mihir

2006-07-27, 1:27 pm

1 >> #ifdef LINUX_OS
2 >> if (_TICKSPERSEC < 1000)
3 >> time_elapsed = (time_elapsed * (1000 / _TICKSPERSEC));
4 >> else
5 >> time_elapsed = (time_elapsed /(_TICKSPERSEC / 1000));[vbcol=seagreen]

On this block i am getting error on 3rd line and 5th line.

The exact error massege is "error: invalid operation to binary *" and
also for the 5th line
"error: invalid operation to binary /"

I have unistd.h included here. And I defined _TICKSPERSEC as
#define _TICKSPERSEC sysconf(_SC_CLK_TCK)

Eric Sosman

2006-07-27, 7:24 pm



Mihir wrote On 07/27/06 14:23,:
> 1 >> #ifdef LINUX_OS
> 2 >> if (_TICKSPERSEC < 1000)
> 3 >> time_elapsed = (time_elapsed * (1000 / _TICKSPERSEC));
> 4 >> else
> 5 >> time_elapsed = (time_elapsed /(_TICKSPERSEC / 1000));
>
> On this block i am getting error on 3rd line and 5th line.


This isn't the same code you posted in the first message.
Let me make a suggestion: Instead of posting approximations
plus explanations, try to construct a short, complete program
that demonstrates the problem -- fifteen or twenty lines ought
to do it, I'd think. The post that entire chunk of code EXACTLY
as it stands: cut and paste, don't re-type. That way, we'll
be debugging the actual code and not a series of approximations.

> The exact error massege is "error: invalid operation to binary *" and
> also for the 5th line
> "error: invalid operation to binary /"


Are these the EXACT error messages? I doubt it ... Again,
learn to cut and paste so as to avoid introducing inaccuracies.

--
Eric.Sosman@sun.com

Bjorn Reese

2006-07-28, 7:27 am

Mihir wrote:
> 1 >> #ifdef LINUX_OS
> 2 >> if (_TICKSPERSEC < 1000)
> 3 >> time_elapsed = (time_elapsed * (1000 / _TICKSPERSEC));
> 4 >> else
> 5 >> time_elapsed = (time_elapsed /(_TICKSPERSEC / 1000));
>
> On this block i am getting error on 3rd line and 5th line.
>
> The exact error massege is "error: invalid operation to binary *" and
> also for the 5th line
> "error: invalid operation to binary /"
>
> I have unistd.h included here. And I defined _TICKSPERSEC as
> #define _TICKSPERSEC sysconf(_SC_CLK_TCK)


I cannot reproduce your problem:

[breese@stellifer:/home/breese/junk] cat ticspersec.c
#include <unistd.h>
#define _TICKSPERSEC sysconf(_SC_CLK_TCK)

int main(void)
{
unsigned long time_elapsed;
if (_TICKSPERSEC < 1000)
time_elapsed = (time_elapsed * (1000 / _TICKSPERSEC));
else
time_elapsed = (time_elapsed /(_TICKSPERSEC / 1000));
return 0;
}
[breese@stellifer:/home/breese/junk] gcc -Wall ticspersec.c
[breese@stellifer:/home/breese/junk]

As Eric said, please provide us with an exact example that fails.

--
mail1dotstofanetdotdk
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com