How do you use the fork() command in such a way that you can spawn 10 processes and have them do a small task concurrently.
Concurrent is the operative word, many places that show how to use fork only use one call to fork() in their demos. I thought you would use some kind of for loop but i tried and it seems in my tests that the fork()...
Are there any C libraries (preferably open source) which are comparable to the GNU Scientific Library (a large library of commonly science & math routines)?
...
I'd like to obscure strings at compile time. I know it can be done in other preprocessors but I haven't found a way to do this with the C preprocessor.
...
Any year evenly divisible by 400 is a leap year (e.g., 2000 was a leap year).
Any other year evenly divisible by 100 is not a leap year (e.g., 1700, 1800 and 1900 were not leap years).
Any other year evenly divisible by 4 is a leap year (e.g., 1996 and 2004 are leap years).
But I'm not sure how to make nested if states in my c-program...
Are there any good Itanium assembly language tutorials?
...
Hi
What is the C equivalent for reinterpret_cast?
Thanks
...
Hello,
I am wondering if there is some way to call C++ code from Common Lisp (preferably portably, and if not, preferably in SBCL, and if not, well, then Clozure, CLisp or ECL).
The C++ would be called inside loops for numeric computation, so it would be nice if calls were fast.
CFFI seems to not support this:
"The concept can be ...
The last line in the following line keeps on generating the " warning C4552: '<=' : operator has no effect; expected operator with side-effect" error, but I don't see any fault in it...
void countDays(void) {
int i=0;
if (birth_month == 2 && birth_day <= 28) {
for ( i <= what_birthday ){
...
I'm using a spin lock to protect a very small critical section. Contention happens very rarely so a spin lock is more appropriate than a regular mutex.
My current code is as follows, and assumes x86 and GCC:
volatile int exclusion = 0;
void lock() {
while (__sync_lock_test_and_set(&exclusion, 1)) {
// Do nothing. This GCC ...
I wanted to ask whether the following statement where printf() has been provided with a type int where it expected a type char will invoke UNDEFINED BEHAVIOUR. If not, what exactly is the step will be taken to make it compatible with expected type. Will a be shortened to char type??
int a = 65;
printf("%c", a);
...
Hi, I came across these two methods to concatenate strings:
Common part:
char* first= "First";
char* second = "Second";
char* both = malloc(strlen(first) + strlen(second) + 2);
Method 1:
strcpy(both, first);
strcat(both, " ");
strcat(both, second);
Method 2:
sprintf("%s %s", first, second);
In both cases the content of both wou...
I am not able to flush stdin here,is there a way to flush stdin?If not then how to make getchar() to take a character as input from user, instead of a "\n" left by scanf in the input buffer??
#include "stdio.h"
#include "stdlib.h"
int main(int argc,char*argv[]) {
FILE *fp;
char another='y';
struct emp {
char name[40];...
Hello,
In my C code , i want to calculate the factorial for numbers in the range 1 to 100. For small numbers, the function works but for bigger numbers for example 100! it returns incorrect result. Any ways to handle factorial of large numbers in C ?. The compiler im using is gcc v4.3.3 .
My code is as follows :
#include <stdio.h>
#inc...
I have a file like this:
...
words 13
more words 21
even more words 4
...
(General format is a string of non-digits, then a space, then any number of digits and a newline)
and I'd like to parse every line, putting the words into one field of the structure, and the number into the other. Right now I am using an ugly hack of reading th...
I have a text file that might contain thousands and thousands of numbers(0-9 --> single digit)/characters, like:
13612371029301276312357829031029352131265309182765236728726355263789120938728...(goes on like this)
In C, how do I read them into an array such that each number gets stored separately?
I mean after storing,
array[0]=1
array[...
Update 3:
Never mind. I kinda got what I was looking for. The following gives unique identifiers inside a class.
static const int _counter_start = __COUNTER__;
static const int val1 = __COUNTER__ - _counter_start;
static const int val2 = __COUNTER__ - _counter_start;
Update 2:
Boost Preprocessor
I will be implementing something ak...
I want to do a ternary search for integers in C ... I have tried it...but it's not working well for particular cases. Please help me to remove the bugs from the following program--
My attempt:
#include<stdio.h>
#include<conio.h>
void tsearch(int *a,int i,int j,int k);
main() {
int a[30],n,i,k;
printf("\nEnter n:");
scanf("...
I only read a little bit about this topic, but it seems that the only benefit is to get around contention problems but it will not have any important effect on the deadlock problem as the code which is lock free is so small and fundamental (fifos, lifos, hash) that there was never a deadlock problem.
So it's all about performance - is t...
I have been dealing with Nasm on a linux environment for some time and this function worked great... but now I am switching to a windows environment and I want to use Masm (with VS2008) I cant seem to get this to work...
void outportb (unsigned short _port, unsigned short _data)
{
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), ...
I understand this code calculates the sum of the args of a variable, however, I don't understand how it works. It looks really abstract to me. Can someone explain how the below works?
Thanks!
#include <stdio.h>
#define sum(...) \
_sum(sizeof((int []){ __VA_ARGS__ }) / sizeof(int), (int []){ __VA_ARGS__ })
int _sum(size_t count, i...