c

Recursion in C with Pre increment

int fact_rec(int n) { printf("%d\n",n); if(n==1) return n; else return fact_rec(--n)*n; //else return n*fact_rec(--n); gives same result //correct output comes for n*fact(n-1) } In the above recursive implementation of the factorial function, fact_rec(5) returns 24. Whereas, if I use n*fact_rec(n-1) in place of n*fa...

Call C API from Groovy

I know that is better to use Python to call Posix and Win API, but I would like to know if there is a not so painful way to call C APIs from Groovy, or at least with Java. ...

call pthread_cond_broadcast with mutex held or not ?

With a pthread_cond_t we have to associate a mutex, When signalling the condition I've seen code such as pthread_mutex_lock(&mutex); //code that makes condition true pthread_cond_broadcast(&cond); pthread_mutex_unlock(&mutex); and pthread_mutex_lock(&mutex); //code that makes condition true pthread_mutex_unlock(&mutex); pthread_...

Bit Reversal

Possible Duplicate: Best Algorithm for Bit Reversal ( from MSB->LSB to LSB->MSB) in C Hi All, I had just written down a bit reversal function and its shown below.I feel its lengthy.So is there any faster and short method or any other alternative which you feel is much more faster and better. Assuming integer is 4 byte...

How do I add an array as an Object Property to a class declared within a PHP extension?

I want my PHP extension to declare a class equivalent to the following PHP: class MyClass { public $MyMemberArray; __construct() { $this->MyMemberArray = array(); } } I'm following the examples in "Advanced PHP Programming" and "Extending and Embedding PHP" and I'm able to declare a class that has integer prop...

Writing and reading long int value in C code

I'm working on a file format that should be written and read in several different operating systems and computers. Some of those computers should be x86 machines, others x86-64. Some other processors may exist, but I'm not concerned about them yet. This file format should contain several numbers that would be read like this: struct Lon...

Absolute path of executable start directory

Hi, I am trying to figure out how to grab the start directory for my program. I am using C and have access to GLib. On the Linux side it is easy, g_get_current_directory as soon as the program is launched, and store this value for later use. I tried using the same method on windows but g_get_current_directory returns whatever %APPDATA% ...

Most Common C / C++ Compiler for NetBeans and Windows

What is the most commonly used (simplest) C / C++ compiler used on Windows when using the NetBeans IDE (6.7)? I want to write (mostly) simple C programs. I have Cygwin installed but for some reason NetBeans doesn't like it. I'm getting a error from it and before I try to figure this out, I thought I should find and (if needed) configur...

Why does the compiler assume that malloc returns an int?

I'm aware that in C it's best practice to never cast the return value of malloc(). I've read that the compiler assumes that malloc() returns an int if you don't include stdlib.h. Of course it would produce an error if you tried to implicitly assign an int to something that's not an int, but that error could be covered up by an explicit c...

pass array by reference in c

How can I pass an array of struct by reference ? example : struct Coordinate { int X; int Y; }; SomeMethod(Coordinate *Coordinates[]){ //Do Something with the array } int main(){ Coordinate Coordinates[10]; SomeMethod(&Coordinates); } ...

How does blocking mode in unix/linux sockets works?

Does blocking mode put that particular task in a "Process Wait" state, as i think non-blocking sockets needs a "busy-wait" or "spin-lock" implementation, explicitly from the user. Or blocking mode sockets are nothing but implicit-implementations of busy-wait by the kernel. In locking mechanisms like semaphores/mutexes/monitors a lock is...

What are trade offs for "busy wait" vs "sleep"?

This is in extension to my previous question http://stackoverflow.com/questions/1107391/how-does-blocking-mode-in-unix-linux-sockets-works What i gather from Internet now, all the process invoking blocking calls, are put to sleep until the scheduler finds the reasons to unblock it. The reasons can vary from buffer empty to buffer full ...

How does a "kill" work? And especically how does a "kill" work on blocked proces?

Who in the kernel is responsible for killing a process. What if a "kill" comes, and the process is in the blocked state. Does the kill waits until the process comes to running state to clean himself. If someone can answer more in terms of kernel, like when a SIGINT from the kill command is generated, what all is invoked by the kernel...

Tell difference between Vista and XP [C]

Is their a way in C to diferentiate between Vista and XP. Reason being is the the path I use is different in both. ...

C/C++ Determine Drive a program is running on

I have been having a problem identifying a flash drive in my code. Luckily my code can be run from the flash drive. So is there a way in C (or C++) to tell what drive letter (or drive name) a program is running on? Reason I need to know is when I plug the USB drive in, it is running a program that copies files from the computer to the ...

why do i always get the same sequence of random numbers with rand() ?

this is the first time i m trying random numbers with c (i miss c#) here is my code int i , j= 0; for(i=0;i<=10;i++){ j = rand(); printf("j = %d\n",j); } with this code i get the same sequance everytime the code but it generates random sequences if i add srand(/*somevalue/*) before the for loop . can someone explain why ? ...

Produce keyboard Events key hits

How to make a simple C program which will produce keyboard key hits. if ( condition ) { KeyPress('A'); } I am working on Ubuntu 8.10 Linux OS ...

Do Intel and AMD processor have the same assembler?

The C language was used to write UNIX to achieve portability -- the same C language program compiled using different compilers produces different machine instructions. How come Windows OS is able to run on both Intel and AMD processors? ...

Accessing Function Variable After calling it while Being in main()

Hi, I want to access variable v1 & v2 in Func() while being in main() int main(void) { Func(); int k = ? //How to access variable 'v1' which is in Func() int j = ? //How to access variable 'v2' which is in Func() } void Func() { int v1 = 10; int v2 = 20; } I have heard that we can access from Stack. But how to do....

C pointers Question

For : int *a; a is an address where an integer can be stored. &a is an address where a is stored. Then, where is &a stored? And, where is &(&a) stored? And, where is &(&(&a)) stored? Where does this storing of addresses stop? ...