c

Definitive function for get elapsed time in miliseconds

I have tried clock_gettime(CLOCK_REALTIME) and gettimeofday() without luck - And the most basic like clock(), what return 0 to me (?). But none of they count the time under sleep. I don't need a high resolution timer, but I need something for getting the elapsed time in ms. Thanks. EDIT: Final program: #include <iostream> #include <...

use win32 API to see whether a Windows XPe system has got USB2 or just 1.1.

Is there a way, just using the win32 API, to find out what version of USB is available? The XPe build is pretty barebones and doesn't doesn't have WMI. I considered the USBview technique: enumerate the USB hubs by opening \.\HCD0 through say \.\HCD9, use DeviceIoControl to get the hub name, and looking for an enhanced host controller. ...

Programming in presence of watchdog timer

Hi, I am new to embedded systems programming, although I have done courses during studies, practical programming is still a bit further away. Here is the problem: I have to program a small system on NXP LPC2103 microcontroller (ARM 7 based), without an operating system. It has a watchdog timer which needs to be regularly updated. The s...

check if carry flag is set

Using inline assembler [gcc, intel, c], how to check if the carry flag is set after an operation? ...

gcc warning in pointer to function (incompatible pointer type)

I need help with gcc warning,looks like im doing something wrong here unsigned long convert_syslog(char *date,int year) { char withyear[1024]; struct tm tm; time_t epoch = (time_t) NULL; snprintf(withyear,sizeof(withyear),"%s %i",date,year); if(strptime(withyear,"%b %d %H:%M:%S %Y",&tm)) { epoch = mktime...

Linking time "undefined reference to " errors

Hi All, I'm having a hard time writing makefiles. I have experience in using the extern variables, when I build the project without using makefiles I get absolutely no errors and I can run the program. But from the time I wrote the makefile to build the project, I'm getting undefined reference to errors. I have more than 3 files with ...

Is there a good way to force type incompatibility in C?

For purposes of type checking I would like to define a function on the lines of void myfunc(type1 a, type2 b) { ... } where type1 and type2 are both typedefed to uint8_t. So far so good, but for sanity and checking purposes (think DbC) I would like to prevent the function being called with a type2 value for the first parameter or a t...

Finding the maximum subsequence binary sets that have an equal number of 1s and 0s

I found the following problem on the internet, and would like to know how I would go about solving it: You are given an array ' containing 0s and 1s. Find O(n) time and O(1) space algorithm to find the maximum sub sequence which has equal number of 1s and 0s. Examples: 10101010 - The longest sub sequence that satisfies...

Is there a way to make a function global to the library and to those who include/link the library?

Hey all, I'm a bit confused now. I thought that when you used extern on a function, it would become global to everything, but it doesn't seem so... What I want right now, is to have some set of functions that I can use in my static library and in the program that links it. How do I that? I'm using Objective-C ...

How do I return an array of strings from a recursive function?

How do I return an array of strings from a recursive function? For example:: char ** jumble( char *jumbStr)//reccurring function { char *finalJumble[100]; ...code goes here...call jumble again..code goes here return finalJumble; } Thanks in advance. ...

Bad pointer type with a typedef

I'm having troubles when calling a function taking a pointer to a string as a parameter. I need to get an Element's name. // method void getStringFromCsv( char ** str ); Let me introduce the structures I'm working with (not written by me and part of a much bigger project, I can't modify them). // typedefs typedef char T_CHAR64[...

Efficient memory reallocation question

Let's say I have a program(C++, for example) that allocates multiple objects, never bigger than a given size(let's call it MAX_OBJECT_SIZE). I also have a region(I'll call it a "page") on the heap(allocated with, say, malloc(REGION_SIZE), where REGION_SIZE >= MAX_OBJECT_SIZE). I keep reserving space in that page until the filled space e...

c interview question

In the following code segment what will be: the result of function value of x value of y { unsigned int x=-1; int y; y = ~0; if(x == y) printf("same"); else printf("not same"); } a. same, MAXINT, -1 b. not same, MAXINT, -MAXINT c. same , MAXUINT, -1 ...

Any weird purpose of switch / default in this code?

Hi, I am porting some code from C to C++ and I found this code: if(ErrorCode >= SOME_CONSTANT) { Status = RETVAL_OK; switch ( ErrorCode ) { default: Status = RETVAL_FAILED; break; } } This code generates a compilation warning: warning C4065: switch statement contains 'default' but no ...

Why to use garbage collector?

Possible Duplicate: Garbage Collection in C++ why? Hi, I read few articles about Garbage Collectors, and still there is one thing I just don´t understand - why use garbage collection? I will try to explain my thoughts: Garbage Collector should release dynamically allocated memory back to system in case there is no need for ...

AES CTR 256 Encryption Mode of operation on OpenSSL

Im new to OpenSSL, Can anybody give me a hint in how to initialize AES CTR mode from a C file. I know this is the method´s signature but I am having problems with the parameters, there´s not many documentation neither a clear example how to make a simple encryption. I would appreciate if somebody could exemplify a call to this method. Th...

reversible float sort in c/c++

I need to sort some arrays of floats, modify the values, and then construct an array with the original ordering, but the modified values. In R, I could use the rank() and order() functions to achieve this: v a vector v[order(v)] is sorted v[i] goes in the rank(v)th spot in the sorted vector Is there some equivalent of these functions...

Combine directory and file path - C

As part of learning C, I wrote the following code to combine directory name with file name. Eg: combine("/home/user", "filename") will result in /home/user/filename. This function is expected work across platforms (atleast on all popular linux distributions and windows 32 and 64bit). Here is the code. const char* combine(const char* p...

Convert some code from C++ to C

Possible Duplicate: C code compiles as C++, but not as C Edit: I recompiled the source for the library as C, and that fixed it. I've got this code I need to use in my application. It's for writing to the serial port, and I can't figure out how to get it to run in C. I've got a version in C++, as well as a version that looks ...

defining object macros

Hello, gcc 4.4.4 c89 I have seen this in some code I am maintaining. #define FALSE 0 #define TRUE (!FALSE) is there any difference in writing the following: #define FALSE 0 #define TRUE 1 Its been used in some functions like this: if(condition failed) { return FALSE; } else { return TRUE; } Many thanks for any suggesti...