c

TDD framework for C

I am a ruby programmer and I really like to do TDD. Right now, I am programming a little bit in C, but I like my tools and the way I program with ruby. So, I am searching for a framework to do unit tests in C. What do you can tell me about it? I already found some options, like: cunit, cmockery, CuTest and others. The problem is, I don'...

Initialization between types "const int** const" and "int**" is not allowed, why?

Using V1.8 z/OS XL C compiler, with warnings jacked-up using INFO(ALL), I get the following warning on line 4 of the code below: WARNING CCN3196 Initialization between types "const int** const" and "int**" is not allowed. 1 int foo = 0; 2 int *ptr = &foo; 3 const int * const fixed_readonly_ptr = ptr; 4 const int...

Per thread CPU statistics in Linux

I want to report the amount of CPU time used per thread in a server process (written in C/C++ on Linux). I can't find the equivalent of GetThreadTimes() on Windows, but that's what I'm looking for. Can anyone point me in the right direction? ...

__attribute__ ((__aligned__)) not working with static variables

This has been driving me nuts for days. I can't get an array to align to 16 if I declare it as static. Any help greatly appreciated. Revised Version: #include <stdio.h> #include <assert.h> #define MAX_INPUTS 250 int main() { float input[MAX_INPUTS] __attribute__ ((__aligned__(16))); printf("Address of input: %p\n", input); printf("...

C Programming. Calculate Elapsed Time in Milliseconds (UNIX)

I want to calculate the time in milliseconds taken by the execution of some part of my program. I've been looking online, but there's not much info on this topic. Any of you know how to do this? ...

fprintf question

I am not asking how to do file I/O, its just more of a formatting question. I need to write a variable number of characters to a file. For example, lets say I want to print 3 characters. "TO" would print "TO" to a file. "LongString of Characters" would print "Lon" to a file. How can I do this? (the number of characters is defined in ano...

why can't I import the 'math' library when embedding python in c?

I'm using the example in python's 2.6 docs to begin a foray into embedding some python in C. The example C-code does not allow me to execute the following 1 line script: import math Using line: ./tmp.exe tmp foo bar it complains Traceback (most recent call last): File "/home/rbroger1/scripts/tmp.py", line 1, in <module> i...

32 bit Address Location confusion... (C Programming)

In C, we can place "&" before a variable to figure out the address of that variable. I have a 32 bit machine. Whenever I print the address in the console, the console displays a 7 digit base 10 number. I just want to know how's that number (10^7) related to the 32-bit machine. (2^32) Thanks ...

C and pointer notation

Opening up the Postgres codebase, I see that much of the C code is written by having pointers with the -> notation in such a way that: (foo)->next = 5; I know that pointer notation has levels of precedence, such that -> = (*foo). and is not the same as *foo. However, does it mean anything when the parentheses are outside the variable...

Help me understand this C code (*(void(*) ()) scode) ()

Source: http://milw0rm.org/papers/145 #include <stdio.h> #include <stdlib.h> int main() { char scode[]="\x31\xc0\xb0\x01\x31\xdb\xcd\x80"; (*(void(*) ()) scode) (); } This papers is tutorial about shellcode on Linux platform, however it did not explain how the following statement "(*(void(*) ()) scode) ();" works. I'm using the boo...

Converting array characters in C Programming

why do I get a from the console with the following code? char array1[] = "Hello World"; char ch = array1; printf(" %s" , ch); (we are instructed not to do this with a pointer....) ...

FindFileFirst() Invalid handle value for every path

I'm trying to get FindFileFirst() windows API call to work and it's totally failing on every attempt. I've tried ., C:\., .txt, C:\.txt and yet it doesn't even iterate down directory names. Not sure what to try anymore. I'm getting ERROR_FILE_NOT_FOUND 2 (0x2) back when I call GetLastError(). Thanks for any help you can give. HANDLE hFi...

Converting Letters to Numbers in C

Hello, I'm trying to write a code that would convert letters into numbers. For example A ==> 0 B ==> 1 C ==> 2 and so on. Im thinking of writing 26 if statements. I'm wondering if there's a better way to do this... Thank you! ...

Assigned variable randomly changes value everytime the program executes (C Programming)

int x = "H"; printf("x is %i\n", x); I get a random 8 digit number from the console everytime I execute the above code... I have given X a definitely value, but why do I get a random value at every execution? Thank you! ...

Easy C longest line copying program...

This is variation of one of exercises from Kernighan C book. Basically prints the longest line from standard input. My question is, if looking at the 'copy method', how does the copy method actually work if it returns void. I'm coming from Java and learning C for the first time. In the copy method, the to and from char arrays are local....

Arrays vs Local variables in C Programming

The following code is trying to make a point (probably the difference between arrays and local variables) I only have a vague idea on the code. Would someone please elaborate? Thanks void doit(int x[10], int y) { y = 30; x[0] = 50; } void main(void) { int x[10]; int y = 3; x[0] = 5; printf("x[0] is %d and y is %...

Controlling mouse in linux

Basically I'm currently using the wiiuse library to get the wiimote working on linux. I want to now be able to control the mouse through the IR readings. Can somebody point me in the right direction as to how to approach this? I know of uinput but there doesn't seem to be a lot of tutorials/guides on the web. I'm working with c/c++ so ...

How to improve performance of file reading by multiple threads?

I need to read a single file using multiple threads under Linux. There are reading operations only and no need of writing. The file reading don't need read the whole file every time. It need read one or more portions of a file every time. I store the offset of each portion beforehand. The file is too large to put into main memory. So ...

viewing the stack when a crash happens

hi, i am using AIX OS.here i am facing a problem that when ever the process crashes there is no stack written in the log.it just gives an information of signal1/10/4 has occured. but no stack is shown. since the code is an optimized code i am even not able to debud using dbx.gdb is not installed. could you please suggest how to see the ...

Whereto put "plugins" in linux

I am currently developing/hacking an image analyzing/transforming tool. The filters therein will be loaded at runtime using dlopen&co. My question is where do *nix tools usually put plugins (*.so files) when installed? bin/program lib/program/plugins/thisandthat.so maybe? Secondly how do I use it and where do I put it during develop...