c

optimize a program with inotify

hello everybody i write a program by inotify to check file change in loop for grab any changes to that. but i think this can be done better. can anybody write this code better? #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/types.h> #include <linux/inotify.h> #include <sys/select.h> #define EVENT_SIZE ( sizeof ...

intializing a structure array using memset

Hello, gcc 4.4.4 c89 I have the following structure. struct device_sys { char device[STRING_SIZE]; int id; char category; }; int main(void) { struct device_sys dev_sys[NUM_DEVICES]; memset(dev_sys, 0, (size_t)NUM_DEVICES * sizeof(dev_sys)); return 0; } I get a stack dump when I call memset. Is this not th...

Is this a double free in C?

Normally, if a pointer is freed twice, it's a double free. For example, char *ptr; ptr=malloc(5 * sizeof(*ptr)); free(ptr); free(ptr); The above code is considered as double free. Is the following considered as double free as well? char *ptr; char *ptr1; ptr=malloc(5 * sizeof(*ptr)); ptr1=ptr; free(ptr); free(ptr1); Thank you. ...

Asynchronous function call for C++

Hi, I need a hint how to implement asynchronous function calls in C/C++ ( or names of frameworks/API calls for windows and/or linux ) The use case is following: A parent thread calls a function. The function creates a child thread and returning, so call is non-blocking and parent thread can continue to do some job. For example pthrea...

A Sane generic cleanup?

I would like to learn a generic cleanup approach which applies to a scenario like the following. Please remember that this is just a -=SAMPLE=-. #include <stdio.h> #include <stdlib.h> int main(void) { unsigned char *uchar1, *uchar2, *uchar3; if ((uchar1 = malloc(sizeof(*uchar1) * 10)) == NULL) { fprintf(stderr, "Error: malloc(...

Win32 API Console Programming in C.

I am stuck with the problems like, reading text from a specific location (x=10, y=5) on the console window. Where can I find a detail tutorial on Win32 API Console mode programming in C? ...

c while loop entry

hi somebody please explain me why int i=0,j=10; while(j>0,i++){ printf("%d%d",i,j); j--; } will not work and int i=0,j=10; while(i++,j>0){ printf("%d%d",i,j); j--; } works. Also please tell me why int i=0,j=10; while(j>0,++i){ printf("%d%d",i,j); j--; } gives an infinite loop ? thanks and regards ...

Struggling to convert CRC-16 0x8408 reversed from C to Java

I've received the task to convert a CRC routine from C to java but I'm really struggling to get the CRC to match up with the documented example. Here's my documentation: The algorithm used is CCITT-16 (0x1021 or 0x8408 reversed).The remainder is initialized to all 1's (0xFFFF) WORD crc16_lsb(BYTE *pData, WORD length) { B...

how to estimate parameters in a mixture of two different distributions using R or any other programming language?

I have to estimate parameters of a mixture distribution which consists of Pareto distribution and Exponential distribution. I am using maximum likelihood estimation procedure by using log likelihood function and differentiating it with respect to each parameter.Since the log likelihood equation is non linear, I have to use Newton Rhapson...

How do you keep track of your progress while reading about a new technology or language?

I just started reading an book on Linux kernel in my free time. Its my first book on this topic so to me everything seems important so I got overloaded by the information very soon. I have tried to quit many times but really cant as I love this subject. My question for all the experts here is how you tackle this while reading new topic/...

Why would GLU crash at this spot?

I have found that my application crashes with a null reference exception right here in sweep.c in GLU source code: static void ConnectLeftVertex( GLUtesselator *tess, GLUvertex *vEvent ) /* * Purpose: connect a "left" vertex (one where both edges go right) * to the processed portion of the mesh. Let R be the active region * containi...

I would like to do some programming stuff during summer, what do you recommend?

Preferable C/C++, Python or Java. I'm tired of doing simple and silly applications. I would like to start or help in a big project, but I don't know how to do it and what to do. Any idea? ...

Is it bad practice to have an application which ships with lots of DLL's?

Is it better to have lots of DLL dependencies or better to static link as mich as possible? Thanks ...

What happens in an interrupt service routine?

Can someone please explain to me what happens inside an interrupt service routine (although it depends upon specific routine, a general explanation is enough)? This always used be a black box for me. ...

Data structure for matching sets

I have an application where I have a number of sets. A set might be {4, 7, 12, 18} unique numbers and all less than 50. I then have several data items: 1 {1, 2, 4, 7, 8, 12, 18, 23, 29} 2 {3, 4, 6, 7, 15, 23, 34, 38} 3 {4, 7, 12, 18} 4 {1, 4, 7, 12, 13, 14, 15, 16, 17, 18} 5 {2, 4, 6, 7, 13, 15} Data items 1, 3 and 4 match the set beca...

Convert a dll to a lib for static linking?

Is there a free way to statically link a dll? I've tried dll to lib but $999 is too expensive. What are alternatives since I want to have 1 nice exe instead of 1 exe + 1 DLL. Thanks ...

Are many static variables in functions using up to much memory?

Hi, I want to write a cross-plattform wrapper for some OS specific (Linux/MacOSX/Windows) calls to get the number of cores of the CPU etc. My idea was to put all of them in single functions with static variables, so stuff like the number of cores that does not change will be processed only once. int getNumCPUCores() { static int nu...

Question Regarding Dynamic memory allocation

Hello guys, I have questions regarding stacks and dynamic memory allocation. 1) Does kernel determine the size of the stack dynamically during run time or sets the size before the load time ? If stack size is allocated dynamically how can stack overflow take place (Because if size of stack reaches beyond the limit the page handler wil...

Flow of Startup code in an embedded system , concept of boot loader ?

hi, I am working with an embedded board , but i don't know the flow of the start up code(C/assembly) of the same. Can we discuss the general modules/steps acted upon by the start up action in the case of an embedded system. Just a high level overview(algorithmic) is enough.All examples are welcome. /Kanu__ ...

how to write binary search program in c

how to write binary search program in c using recurssion ...