Hello,
I am trying to use an alternative Sleep() function in C that has a better solution. (The solution of sleep() is only 15 ms). I need 1 ms. My teacher gave me the above code
static double esperaH(double *temp) //sleep in ms
{
bool resultado;
unsigned _int64 *now, *frec,goal;
//LARGE_INTEGER *now, *frec, goal;
now = (unsigned _int64*)calloc(1,sizeof(no
w));
//now = (LARGE_INTEGER*)calloc(1,s
izeof(now)
);
resultado = QueryPerformanceCounter(no
w);
frec = (unsigned _int64*)calloc(1,sizeof(fr
ec));
//frec = (LARGE_INTEGER*)calloc(1,s
izeof(frec
));
resultado=QueryPerformance
Frequency(
frec);
goal = *now + (unsigned _int64)((*temp*1.0e-3)*(*f
rec));
while (goal > *now)
resultado = QueryPerformanceCounter(no
w);
return ((double)*now/(double)*fre
c)*1000;
//return ((LARGE_INTEGER)*now/(LARG
E_INTEGER)
*frec)*100
0;
}
if I compile it like this I get the following warnings/errors:
--------------------Config
uration: pci 1784 configuration5 - Win32 Debug--------------------
Compiling...
pci 1784 configuration5.cpp
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(110) : warning C4305: 'argument' : truncation from 'const double' to 'float'
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(55) : warning C4101: 'num_contador' : unreferenced local variable
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(387) : warning C4244: 'argument' : conversion from 'unsigned long' to 'unsigned short', possible loss of data
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(426) : warning C4244: 'argument' : conversion from 'const double' to 'unsigned char', possible loss of data
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(728) : error C2664: 'QueryPerformanceCounter' : cannot convert parameter 1 from 'unsigned __int64 *' to 'union _LARGE_INTEGER *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(732) : error C2664: 'QueryPerformanceFrequency
' : cannot convert parameter 1 from 'unsigned __int64 *' to 'union _LARGE_INTEGER *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(737) : error C2664: 'QueryPerformanceCounter' : cannot convert parameter 1 from 'unsigned __int64 *' to 'union _LARGE_INTEGER *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
pci 1784 configuration5.obj - 3 error(s), 4 warning(s)
If I compile it using _int
If I use the other code version:
static double esperaH(double *temp) //sleep in ms
{
bool resultado;
//unsigned _int64 *now, *frec,goal;
LARGE_INTEGER *now, *frec, goal;
//now = (unsigned _int64*)calloc(1,sizeof(no
w));
now = (LARGE_INTEGER*)calloc(1,s
izeof(now)
);
resultado = QueryPerformanceCounter(no
w);
//frec = (unsigned _int64*)calloc(1,sizeof(fr
ec));
frec = (LARGE_INTEGER*)calloc(1,s
izeof(frec
));
resultado=QueryPerformance
Frequency(
frec);
goal = *now + (LARGE_INTEGER)((*temp*1.0
e-3)*(*fre
c));
while (goal > *now)
resultado = QueryPerformanceCounter(no
w);
return ((double)*now/(double)*fre
c)*1000;
//return ((LARGE_INTEGER)*now/(LARG
E_INTEGER)
*frec)*100
0;
}
...I get the following compiler warnings/errors:
--------------------Config
uration: pci 1784 configuration5 - Win32 Debug--------------------
Compiling...
pci 1784 configuration5.cpp
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(110) : warning C4305: 'argument' : truncation from 'const double' to 'float'
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(55) : warning C4101: 'num_contador' : unreferenced local variable
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(387) : warning C4244: 'argument' : conversion from 'unsigned long' to 'unsigned short', possible loss of data
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(426) : warning C4244: 'argument' : conversion from 'const double' to 'unsigned char', possible loss of data
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(728) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(732) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(734) : error C2677: binary '*' : no global operator defined which takes type 'union _LARGE_INTEGER' (or there is no acceptable conversion)
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(736) : error C2678: binary '>' : no operator defined which takes a left-hand operand of type 'union _LARGE_INTEGER' (or there is no acceptable conversion)
C:\datos\judith\proyecto_j
udith\pci 1784\pci 1784 configuration5.cpp(736) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
pci 1784 configuration5.obj - 3 error(s), 6 warning(s)
I don´t know what to do. The Query-fungtions seem to only accept large_integer, but large_integer cannot operate with +,*,/
Does anyone have a suggestion what could be my error or how I could solve my problem?? I would be so glad since I am very unexperienced in programming.
Judith
Start Free Trial