c

Sending structure using recvfrom() and sendto()

I am using C language which is a common platform for both the server and the client. I have a structure of a particular type which I want to send to the client from the server. For e.g. SERVER CODE //necessary declarations struct hostent *hp; hp=gethostbyname("www.google.com"); sendto(sockDes,&hp,sizeof(hp),0,(struct sockaddr *)&...

binary sequence detector

Does anyone know of an optimized way of detecting a 37 bit sequence in a chunk of binary data that is optimal. Sure I can do a brute force compare using windowing (just compare starting with index 0+next 36 bits, increment and loop until i find it) but is there a better way? Maybe some hashing search that returns a probability that the s...

Why do I get a warning everytime I use malloc?

If I use malloc in my code: int *x = malloc(sizeof(int)); I get this warning from gcc: new.c:7: warning: implicit declaration of function ‘malloc’ new.c:7: warning: incompatible implicit declaration of built-in function ‘malloc’ I'm new to C. Am I doing something wrong? ...

Using 'color' to define object's flag status?

I'm asking this question because it isn't the first time I saw this coding practice, but never saw any commentary about the reason for this: I was browsing the Lua's source and saw that they use 'colors' (white, black) to describe the state of an object. Here is the code from header lgc.h: /* ** Layout for bit use in `marked' field: ** ...

C/C++ documentation tool

What are the C/C++ documentation tools that you have used? Which one would you recommend? I have used doxygen with graphviz but it seems to have a problem with large code bases especially when generating collaboration diagrams. I found DoxyS on the web but have not used it. Going by the documention on its homepage it looks like its wor...

Pointer question

Okay I go through 2 layers of functions fun1 calls func2 calls func3 . I pass a pointer all the way down using basically int *ptr, at the lowest "level" of the call stack I also have another function that dynamically allocates memory for an int array. At the top level (func1 level) I always get null back for the passed pointer. I have tr...

C/Glib Memory Management [no dangling reference > whyy!??] {SOLVED}

Hi everybody I have a program that call a function with undefined arguments, like this: #include <stdargs.h> ... /* code */ int main () { GArray *garray = g_array_new (FALSE, FALSE, sizeof (char *)); /* the code above initialize the GArray, and say that the garray expect a pointer to char. */ function_name (garray, "arg2", "arg3...

Is int in C Always 32-bit?

This is related to following question, http://stackoverflow.com/questions/1229131/how-to-declare-a-32-bit-integer-in-c Several people mentioned int is always 32-bit on most platforms. I am curious if this is true. Do you know any modern platforms with int of a different size? Ignore dinosaur platforms with 8-bit or 16-bit architecture...

Can any one tell me how to write a simple C++ code to export my data(from variable) into PDF file without using any external libraries or utilities?

Can any one tell me how to write a simple C++ code to export my data(from variable) into PDF file without using any external libraries or utilities? ...

Declaring variables inside a switch statement

I saw a few answers to this issue, and I get it — you can't declare and assign variables inside a switch. But I'm wondering if the following is correct at throwing an "error: expected expression before 'int' switch (i) { case 0: int j = 1; break; } Why would putting an NSLog before it result in no errors? switch ...

K&R Qsort example with Pointers and Arrays confusion.

I find it difficult to understand the following snippet of code. I understand the pointer to function mannerism showed, but where I find confusion is in the indicated lines. void qsort(void **v, int left, int right, int (*comp) (void *, void *)) { int i, last; void swap(int **v, int i, int j); if (left >= right) /* do no...

Get the call stack in code with less overhead?

Hi, I am going to implement an internal profiler for memory on linux. I want to save the stack for each malloc/free/realloc. I am trying to use "pstack" to get the stack trace everytime. But the overhead is too high. Is there any lightweigt approach to get the call stack in C code? I know there are some tools like "valgrind, google pro...

Creating multiple thread in JVM to fulfil high user load

I have a C program that will be storing and retrieving alot of data in a Java store. I am putting alot of stress in my C program and multiple threads are adding and retrieving data from Java store. How will java handle such load? Because if there is only one main thread running JVM and handling all the requests from C, then it may become...

Check if a char* buffer contains UTF8 characters?

In the absence of a BOM is there a quick and dirty way in which I can check if a char* buffer contains UTF8 characters? ...

Does free() defragment?

Assuming two blocks allocated by malloc() that are internally next each other(who knows they next each other? just assumption), after free() two blocks, are they emerged into one unallocated block? Not sure, please help. Thanks. ...

Retrieving byte array of unknow length from Java store

I already posted a question regarding it, but at that time I haven't have the account. I got a reply but I was still confused and I cannot continue on that thread. I am re posting the question again along with a link to previous conversation. Returning char array from java to string - JNI The data I am storing in Java is serialized. I...

Setting TCP Retransmission Timeout in C

I have an small server/client test program I am running over a radio link using TCP/IP and I noticed with wireshark that I am getting a lot of retransmits due to high latency. How do I increase the window my program waits for an ACK before attempting retransmission? Update on OS: The server is running Linux, the Client is on Windows ...

Memory leak in C,C++; forgot to do free,delete

Hi All, We allocate memory in C using malloc and in C++ using new. I know that memory allocated must be freed or given back to OS using free in C and delete in C++. If I forgot to use free/delete after allocating memory, it means there will be memory leak. Now, my question is, is this memory leak only during the time period of executio...

Lua and C-struct

how can I use c-struct in lua? ...

Need of PRBS Pattern Generating C/C++ API

Hi, I am looking for PRBS Pattern Generating C/C++ API, So that i can insert it in Payload of UDP. If anybody know the procedure for generating PRBS pattern it would be greatfull. ...