This worked, but only after I put parenthesis around the conditional, like this:
/* A-ok on gcc 4.8 */
const unsigned long s = (long)(clk.tv_sec - recstart.tv_sec) - ((clk.tv_nsec <...
Type: Posts; User: synthetix
This worked, but only after I put parenthesis around the conditional, like this:
/* A-ok on gcc 4.8 */
const unsigned long s = (long)(clk.tv_sec - recstart.tv_sec) - ((clk.tv_nsec <...
Thanks! This what what I ended up using:
struct timespec clk,recstart;
unsigned long min,sec;
if(current_frame==0)
recstart=clk;
sec = (((clk.tv_sec-recstart.tv_sec)*1000) +...
Thanks, Salem. The problem is the tv_nsec member of timespec resets to 0 every second. So if I try to subtract 'start' from 'now,' I eventually get a negative value. I could multiply now by tv_sec,...
I have an app that records frames from a camera and displays a min/sec counter to the user when record is pressed so they know how long the recording has been going. I need this counter to be...
That would be fine except the file reader presents these values as integers, and that's the only way I have access to them.
This works:
uint8_t input = 47;
uint8_t temp = (((input%100)/10)*16)+(input%10);
//result is 71
However, I'd like to avoid the division if possible. Can you see a way to do this through...
Sorry, I should have been more clear. Basically, I need to take a non-negative decimal value and convert it like this:
input decimal value: 10
output hex value: 0x10 (decimal value: 16)
...
I need to convert an integer, for example 10, to its base 16 equivalent, 16. I found this code that converts a base 16 number to base 10, but I need the opposite. Plus, this code doesn't seem to work...
I'm using GCC 4.8.1 (on a Mac). However, I just tried compiling your program on an Ubuntu machine running GCC 4.7.2, and I don't get a warning unless I turn on strict aliasing (-fstrict-aliasing)....
I have a byte array in my code that I need to interpret as a 64 bit integer:
uint8_t stuff[8];
I can cast this to a 64 bit integer like this:
int64_t bigint = *((int64_t*)stuff)
I know, that's why I thought it might be good to ask. I guess this isn't a problem if declaring i at the top of the function (which, I think, you're supposed to to in ANSI C), but if you have a few...
Yes, my mistake. :cool: Thanks.
You can do this in C99:
for(int i=0;i<100;i++){
}
But what if I'm not writing C99 code and want to keep the same behavior? Couldn't I just do this:
Actually yes, it does. Sorry, that was a bad example. The example I should have used was in fact a struct:
struct test{
char a[5];
char b[5];
} test;
memcpy(&test, &((struct...
I was getting "excess elements in scalar initializer" errors from GCC from the following code, even though it still compiled and ran fine:
void *array[] = {
(char){0,1,2,3,4},...
Thanks. I guess I'll just pass the size along with the array for now. I was trying to cut down on the number of parameters passed to function, but this will work for now!
I need to figure out how many bytes are in an array created like this:
int my_array[8];
if I do this, it works as expected:
size_t size = sizeof(my_array); //size is "32"
I have a multithreaded app with a thread that needs to access an int in the main thread that provides status information (e.g. playing or paused). This int may be set and read by either thread. Do I...
Let's say I have a function that sets a number of local variables like this:
void test_func(){
long a = 1; //4 bytes
long b = 2; //4 bytes
long c = 3; //4 bytes
long d = 4; //4 bytes
Thanks. That's a valid point and I certainly agree.
Ah. Good call. I will definitely do that.
Actually, the code I posted was wrong. That line should have used strlen() instead of...
Well, the question wasn't really about which way is "better" or not. I'm more concerned about whether there will be any problems doing it the other way, that is using a generic void*.
Why do you...
I have a pointer-pointer variable that contains strings of characters. It is dynamically added to when more data becomes available. I must first allocate the pointer to each string, and then allocate...
I figured out the problem. I was adding the direction_move vector to the camera position incorrectly. I was adding to separate X,Y,Z vector elements based on key input, where I should have been...
I have a camera in my Open GL ES 2.0 app. Using translation/rotation matrices, I can move and rotate the scene using the WSAD keys for movement/strafe and the arrow keys for rotation. I do this by...
Thanks. That pretty much answers my question!
I was cross compiling, and had to use -nostdlib to prevent linking to the build system's libc (had to point the linker to the target libc manually).