C/C++ :: Time Unit Returned From GetProcessTimes
Jan 25, 2014I have a question about the exact time units returned by the GetProcessTimes function from the Windows API. Is it in seconds or some other unit?
View 3 RepliesI have a question about the exact time units returned by the GetProcessTimes function from the Windows API. Is it in seconds or some other unit?
View 3 RepliesI need to get the current time, have the system sleep for a period of time, then return the difference in seconds.
#include <iostream>
#include <string>
#include <ctime>
#include <time.h>
#define _CRT_SECURE_NO_WARNINGS
using namespace::std;
// in the <ctime> library is a function time(0)
[Code] ....
I'm not receiving an errors but the return value is not correct. It's returning 1.4259 no matter how long it sleeps for.
I am reading the book C Programming Language. On Structures, it says:
"The only legal operations on a structure are copying it or assigning to it as a unit, taking its address with &, and accessing its members."
What does it mean assigning a structure as a unit?
How to Install CPPUnit in Solaris? I don't have gcc in Solaris and all the packages I have downloaded for CPPUnit needs gcc to be compiled.
View 4 Replies View RelatedI am currently trying to send a x264 nal unit using WINSOCK with a reliable multicast socket. It isn't decoding properly, and my initial thought is I am not receiving all the bytes correctly. I was hoping some fresh eyes can provide insight on errors or any improvements. I have seen some topics about this subject, and they showed sending entire structs with the socket. However, I am concerned about endianess so I am trying to stay away from that approach. I have commented out the decoding part, until I am confident that I am receiving the nal unit properly.
Server:
#include <WinSock2.h>
#include <WS2tcpip.h>
#include "wsrm.h"
#include <Windows.h>
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include "x264Encoder.h"
I have implemented the IRepository and UnitOfWork Patterns in my project and I have made a little tweak in the UnitOfWork pattern .
public class UnitOfWork : IDisposable {
private DataContext m_Context = new DataContext();
private bool m_disposed = false;
#region Repositories
private GenericRepository<Product> m_ProductRepository = null;
private List<object> m_RepositoryList = new List<object>();
#endregion
[Code] ....
In my UOW class I have the public property ProductRepository. Now my idea was instead of creating a public property for every repository that I have, I created the generic method GetRepository<T> to dynamically create repositories.
Do you think that this change will have bad side effects. I think that it will improve the maintainability of the code.
I need a random unit vectors in n-dimensional space. how to build it in C++?
View 6 Replies View RelatedI am running a unit test on a library and this line keeps failing on Fedora 16, G++ 4.6.2
Code:
assertNAN(double, std::numeric_limits<double>::signaling_NaN()); //sanity check
The assert looks like this
Code:
//needs to copy it so that if its a function call it only does it once
#define assertNAN(type, one) {
type val = (type)one;
std::string lag(#one);
lag += " not a number";
[Code] ...
I am compiling with -DNDEBUG -O3 -ffast-math -fexpensive-optimizations to simulate a production environment. Is there a way to test for NAN consistently?
I have function that returns historical data. I can access it, using file name. If I use file name, it reads that file and saves it to dictionary, so that in the future, if historical data is required for the same file, it does not read it again (it's lazy loading). If no file is supplied to the function, it tries to read file which is given in app settings.
However, for unit testing, I do not want to read any file. Instead, I want it to use small sample of hardcoded historical data. In order to do that, I think, I need to introduce interface to it. Then I can use some IoC to choose between different implementation for unit testing purpose and ordinary launch of application.
Function to get history is given as follows:
public static class Auxiliary
{
private static Dictionary<string, MyData> _myData;
public static MyData GetData(string fileName = null)
{
// ...
}
}
I have created default Unit Test project with Visual Studio so, as far as I know, by default it uses MSTest as test runner and MSUnit as unit testing framework but it does not have any IoC container so I should manage NuGet packages for solution and install Unity.
As far as I know, MSUnit (aka Moles) can unit test static methods (it's unconstrained isolation framework, like Typemock Isolator, unlike NUnit) but still many people suggest not to use any static methods for unit testing.
Should I use shim or stub [URL] Stubs should be used for faking external dependencies and here it is not external library, but my own code.
I'm new to c++ and boost library also. I need to test a function of my library. For example
// Functions.hpp
int add(const int x, const int y);
//Functions.cpp
int add(const int x, const int y)
{
return (x + y);
}
Now i need to test add function using boost. I need the result or output in below style. What all settings do i need to do in VS 2010 and how i should include boost test in the project.
==== Run unit tests ====
Running 2 test cases...
./mytest.cpp(13): error in "SimpleTestInMainTestingModule": check 1 == 2 failed
Test suite "Master Test Suite" failed with:
1 assertion out of 2 passed
1 assertion out of 2 failed
1 test case out of 2 passed
1 test case out of 2 failed
How can we build unit-tests for functions of libraries, those with user-defined types used as their arguments ?
For example
CRecord func(Myclass * class, BSTR * name, CComptr<xxx> & something);
I am trying to write a unit convertor for converting temperatures Celsius, Kelvin and Fahrenheit.
Code:
if (select_one == 't' || select_one == 'T'){// this one works perfectly...
//This section does not tell you the use of variables.
//The use of variables can be seen as comments in the main program
[Code].....
This part of code will be part of a larger Unit Converter program. Do you think this method of conversion is wise? The error codes are for debugging use only.
I convert all temperatures of all units, whether Celsius, Kelvin or Farhenheit into Celsius and then convert it into the units the user wants.
For example:
Kelvin -----> Celsius ------------------> Farhenheit
(Input) (base of conversion) (desired output unit)
Do you think this type of conversion is okay?
I am working on my final project for my class and after finally getting it to compile with no errors to finding examples/tutorials and following skeleton code I cam encountering a problem.
The program runs, asks all the correct questions but when it displays the base pay and total pay for all 3 employees it comes back as ( -1.0743 blah blah )
When they work over 40 hours it works correctly but when they work under 40 hours it displays those weird numbers in those sections.
// Kevin Johnson -- Overtime Pay -- Final Assignment
// Created 11/14/2013 // Edited 11/17/2013
#include "stdafx.h"
[Code]....
Why is it not okay to return void? Most compilers will probably let you (gcc does) but it gives you a warning that you aren't supposed to. Most languages allow you to return void.
Something like
Code:
void log(const std::string & txt){ std::cout << txt << std::endl; }
//C++ way to do it
void bar(int i){
[Code].....
I have this int type function that returns a number. It returns the value 2 for now but later it will return more variety of values. How do I use the value it returned? I'm not sure of the proper syntax.
View 5 Replies View RelatedThis is my code:
Code:
#include <math.h>
#include <stdio.h>
int main(void) {
float a,b,c,root_1,root_2;
printf("Please enter value a from the quadratic equation
[Code] ......
And I keep getting this error:
Code:
/tmp/ccgtUIun.o: In function `main':
assign345.c:(.text+0xc7): undefined reference to `sqrt'
assign345.c:(.text+0xef): undefined reference to `sqrt'
collect2: ld returned 1 exit status
I've had with visual studio but nothing seems to be working. No matter what I do even with simple programs, like Hello World, I'm always getting an error about a .pch header file.fatal error C1083: Cannot open precompiled header file: 'DebugConsoleApplication1.pch': No such file or directory
This is only for one of the programs I've made but I'm pretty new to programming and I've not even used the header files for anything so I have no clue how to resolve this problem.
I have some struct which contains: void *elems (basically a pointer to an array of contiguous memory).
I want to use bsearch to return a pointer, and then somehow figure out where in the array that value is. Having a pointer in this case isn't enough, I need to know what the index is. I've tried a number of things:
int index;
void *value = bsearch(key, start_ptr, cv->count, cv->elemsz, cmp);
index = &value - &start_ptr;
return index; [
Replacing the second line with:
// in the first instance
index = (char*) value - (char*) start_ptr;
// in other instances...
index = ((char*) value - start_ptr))/cv->elemsz)
But nothing works.
I call a function that returns a string, and I can print it out fine, but I want to test the result of the function to see if it returns 0. But I can't just call the function again (GetNextToken(b)) because it will generate a different token. I can't allocate space for the string because I'm not sure what the size of the returned string is going to be.
Basically I want to see if the GetNextToken(b) returns 0, and if it doesn't then print the string. And running GetNextToken(b) again will give a different result.
Code:
int main(int argc, char **argv) {
SomeStruct* b = CreateStruct(argv[1],argv[2]);
printf("HERE %s", GetNextToken(b));
So, I'm in the midst of implementing my own malloc() and free() functions, but I'm having a hard time with the syntax of getting the address that malloc returns. Whenever I check the address, it's 0 Here's the code:
Code:
char *word = malloc(10);
int address = *word;
printf("%d",address);
The reason I want the address is so that I could store it in a data structure for further usage when I'm dealing with different cases for the free() function. Or is there another way to do this?
What does the C++ standard say about returned temporal objetcts's lifetime ?For example, in this code:
#include <iostream>// Object cout, manipulator endl
using std::cout;
using std::endl;
class C {
private:
[code]....
Here, the temporal object C returned by function f() still lives when function h() is called and is destroyed inmediately after function h() returns to his caller (the function main()). So, it seems that a returned temporal object lives while it is used and it is destroyed when not used (in the next sentence of the sentence that call the function that returns the temporal object). Does the C++ standard specify that this must be the behaviour of C++ compilers?
I'm trying to read a data returned from a web service. How i could extract the juice of this document in c#?
Here's the code
<?php
require_once("nuSOAP/lib/nusoap.php");
//require_once("Classes/Connection.class.php");
//require_once("Classes/Customer.class.php");
require_once("includes/config.php");
[Code] ....
How will i extract the result from the Array Customer?
I want know if the query returned zero rows or not.
Don't want to use count(*)
sql = "select * from TABLE where employeefirstname = @First order by EmploymentStatusDescription";
using (SqlCommand cmd = new SqlCommand(sql, conn)) {
cmd.Parameters.AddWithValue("@First", First);
reader = cmd.ExecuteReader();
} while (reader.Read())
I am just trying to make a simple two player game. First player enters the movie and second player guesses it by using some basics of C++.
movie[] = entered by player 1.
movie_temp[]= a temp array with '_' in it. It updates after every guess by player 2.
MY PROBLEM: Please refer the main function where I called the function movie_check().
This updates the life after every guess. I want the same to happen for my movie_temp array.
When i run this program, only the lives are updated properly, on correct guess the lives are not reduced, but in next turn the array_temp is not updated and the same array is displayed again and again after each gas.
How to create a function which return array and save it in movie_temp (just as I did for life).
IDE: Code::Blocks
Compiler: GCC Compiler
#include<iostream.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<conio.h>
void display_movie(char movie_temp[], int);
void display_life(int);
int win_player2(char movie_temp[]);
[Code] ....
Code:
it = m_CoopTable->m_SparseMap.find(s);
if (it != NULL) //Error
{
return false;
}
This gives me compile-time error. it is an iterator to a hash_map
I randomly get this when I execute my program. Sometimes it happens three times in a row sometimes it can go about 10 times before it shows up again.
I was not able to find out what the error code means, and I can't pinpoint the error. During debugging it NEVER happens, and logging tells me it happens between two cout << operations.
what the error code means?