c

Fork before or after accepting connections?

The following snippet of code creates 4 processes, all sharing the same listening socket. Is there any danger in doing this? Should I always have one listening process and fork after connections are accepted, in the conventional manner? for (p = 0; p < 3; p++) { pid = fork(); if (pid == 0) break; } while (1) { unsigned int cl...

following symbolic links in C

I'm looking to write a C program which, given the name of symbolic link, will print the name of the file or directory the link points to. Any suggestions on how to start? ...

C vs. Java for game programming

I understand that C++ is generally considered better than Java for games (at least larger-scale games). Why is this? What is keeping Java from being competitive in this field? Which reasons against using Java for game programming have the most basis, and which ones are myths? EDIT: Am a bit unfamiliar with C/C++, and did not think to ...

C semaphores and a "barrier" between threads

I'm trying to solve a problem our Operating Systems professor showed us from a previous exam to prepare for the next one. The problem is to have two threads that execute concurrently and may complete in a different amount of time. After a particular thread is completed, it needs to block until the other thread is completed, then they ma...

Any good C++/C NNTP libs?

I came across some crusty and limited efforts awhile back but I was wondering if there was something truly functional that I missed, preferably in C++ but C is better than nothing. ...

C code to get the ip-address

Hi I like to know how to get the ip-address of the local machine using C code ? If there are multiple Interfaces then I should be able to display the ip-address of each interface. NOTE: Do not use any commands like ifconfig within C code to retrieve the ip-address. ...

Why Access Violation for cout And Stack Overflow for printf

Hi, I wanted to know Why Access Violation occurs for cout And Stack Overflow for printf in the following two code snippets. I wanted to know why Access Violation for the First code instead of the Stack Overflow. First Code Which i get Access Violation : void Test(); void Test() { static int i = 0; cout << i++ << endl; ...

Getting the size of the data of a Pointer

I tried the following code in order to see how to get size of the data of a pointer: #include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ char *test_char_ptr = "This is just a test"; int *test_int_ptr = (int *) malloc(16*sizeof(int)); for(int i = 0; i<16; i++){ test_int_ptr[i] = i; } printf("%s\n",te...

Extracting C / C++ function prototypes

I want to do this: extract_prototypes file1.c file2.cpp file3.c and have whatever script/program print a nice list of function prototypes for all functions defined in the given C / C++ files. It must handle multi-line declarations nicely. Is there a program that can do this job? The simpler the better. EDIT: after trying to compile ...

I have a .mp3 file. How can I seperate the human voice from the rest of the sound in C?

Is it even possible in C [I know it is possible in general -GOM player does it]? just let me get started... What do you say? How exactly do you identify human voice distinguished from other sounds? ...

Passing large C structure through JNI efficiently

I have a large C structure (about 40 members, int and char[]) which I have to pass through JNI to the Java side for further processing. This happens repeatedly. (I already put the GetMethodID() etc. into an init() function on the C side so I only have to call them once.) What would be an efficient way to do this? I can think of: Inst...

what is the assert function

hi i ve been studying on openCV tutorials and came across with the "assert" function what does it do thanks ...

Pros and Cons of Different macro function / inline methods in C

According to the C FAQ, there are basically 3 practical methods for "inlining" code in C: #define MACRO(arg1, arg2) do { \ /* declarations */ \ stmt1; \ stmt2; \ /* ... */ \ } while(0) /* (no trailing ; ) */ or #define FUNC(arg1, arg2) (expr1, expr2, expr3) To clarify this one, the arguments are used in ...

Trigonometric functions on embedded system

sin and cos functions are slow and need a lot of resources to run on embedded systems. How does one calculate sin and cos functions in a more resource-saving and faster way? ...

When could a call to time(NULL) fail on Linux

According to this documentation http://www.cplusplus.com/reference/clibrary/ctime/time/ for time(NULL) "If the function could not retrieve the calendar time, it returns a -1 value." Is this something I should check for in my code? Surely something has got to be going pretty wrong if time(NULL) is not retrieving the time. ...

size_t is pointer size in practice

Hi C++ gurus, Let me first clarify that I am by now very familiar with definitions of size_t and intptr_t, and I don't want any repetitions of what they accomplish. Instead I would like to know the following. Do you know of any platform, except x86/DOS (with its unbearable memory models) where the cast void* a = ...; size_t b = (size_...

Python Vs C - Handling environment variable in Windows

Hi Guys, I see a variation in output between C and python code in Windows trying to get the same functionality. The c code ( similar to unix shell scripts ) shows the TEST1 environment variable in 'test.bat.output' with its value as empty string whereas the python code removes this environment variable. Is there a way to ask Python ...

Fastest way to scan for bit pattern in a stream of bits

I need to scan for a 16 bit word in a bit stream. It is not guaranteed to be aligned on byte or word boundaries. What is the fastest way of achieving this? There are various brute force methods; using tables and/or shifts but are there any "bit twiddling shortcuts" that can cut down the number of calculations by giving yes/no/maybe co...

Testing Code for Embedded Application

Background: I am developing a largish project using at Atmel AVR atmega2560. This project contains a lot of hardware based functions (7 SPI devices, 2 I2C, 2 RS485 MODBUS ports, lots of Analogue and Digital I/O). I have developed "drivers" for all of these devices which provide the main application loop with an interface to access the...

How can I print a C double bit-by-bit to see the low-level representation?

I want to learn how the computer represents the double type in bit, but the & and | bit operators can't use double. And memcpy(&d, &src, 8) also doesn't seem to work. Any suggestions? ...