c

What makes you a C programming expert?

I attended a job fair yesterday and a developer asked me how I would rank my proficiency in C. I then realized that this is incredibly arbitrary and almost impossible to nail down, so my question is what knowledge makes you an expert in programming C? Edit: or what would the breakdown be? what makes you good, decent, proficient, etc. ...

looking for a tuple matching algorithm

I need to implement an in-memory tuple-of-strings matching feature in C. There will be large list of tuples associated with different actions and a high volume of events to be matched against the list. List of tuples: ("one", "four") ("one") ("three") ("four", "five") ("six") event ("one", "two", "three", "four") should match list i...

Memory footprint issues with JAVA, JNI, and C application

I have a piece of an application that is written in C, it spawns a JVM and uses JNI to interact with a Java application. My memory footprint via Process Explorer gets upto 1GB and runs out of memory. Now as far as I know it should be able to get upto 2GB. One thing I believe is that the memory the JVM is using isn't visible in the Pro...

Oriented Bounding Box vs Oriented Bounding Box intersection test (c/c++)

I'd like an optimized implementation for this test. It need not conform exactly to this prototype. bool OOBBIntersectOOBB( float center0[3], float halfExtents0[3], // or some other bounding description float rotation0[9], // quaternion would also be fine float center1[3], float halfExtents1[3], float rotation1[9]); ...

How do I convert between big-endian and little-endian values in C++?

How do I convert between big-endian and little-endian values in C++? EDIT: For clarity, I have to translate binary data (double-precision floating point values and 32-bit and 64-bit integers) from one CPU architecture to another. This doesn't involve networking, so ntoh() and similar functions won't work here. EDIT #2: The answer I ac...

C pointer Q: malloc inside a fn call appears to be getting freed on return of fn?

I think I've got it down to the most basic case: int main(int argc, char ** argv) { int * arr; foo(arr); printf("car[3]=%d\n",arr[3]); free (arr); return 1; } void foo(int * arr) { arr = (int*) malloc( sizeof(int)*25 ); arr[3] = 69; } The output is this: > ./a.out car[3]=-1869558540 a.out(4100) malloc:...

int matrix with pointers in C - memory allocation confusion

Hello! I'm having some issues with producing an int matrix without creating memory leaks. I want to be able to make a given (global) matrix into any size dynamically via read_matrix(). But then i want to be able to free the memory later on. So in my main method the second printf should result in a bus error since it should not have any ...

How can one grab a stack trace in C?

I know there's no standard C function to do this. I was wondering what are the techniques to to this on Windows and *nix? (Windows XP is my most important OS to do this on right now.) Thanks for the help! ...

How do I access a char ** through ffi in plt-scheme?

I'm mocking about with plt-scheme's ffi and I have a C-function that returns a char ** (array of strings). If I declare my function as (_fun _pointer -> _pointer), how do I convert the result to a list of strings in scheme? Here are the relevant C-declarations: typedef char **MYSQL_ROW; /* return data as array of strings */ // ... MY...

Stack overflow problem!

You may think that this is a coincidence that the topic of my question is similar to the name of the forum but I actually got here by googling the term "stack overflow". I use the OPNET network simulator in which I program using C. I think I am having a problem with big array sizes. It seems that I am hitting some sort of memory allocat...

What is the recommended version of GNU autotools?

We maintain a RPM based software distribution at work so that we have a common set of software across all the platforms that we support. As a result we have to build a lot of third party software, and frequently find situations where we need to run autoconf/automake/libtoolize/etc to get it to build on Solaris or another platform. I'...

What sorts of simple IDL parsers / code generators are available for C / C++ code?

For a project I'm working on, I need to have a lot of source code files generated from an interface description. That description is currently IDL (really, a pidgin IDL-like language), but I'm not married to it and am willing to consider alternatives. What sorts of code generators are available that can take IDL (or something like it) ...

Pointers and Reference

I understand the overall meaning of pointers and references(or at least I think i do), I also understand that when I use new I am dynamically allocating memory. My question is the following, if i were to use cout << &p it would display the "virtual memory location" of p. Is there a way in which I could manipulate the "virtual memory loca...

Closing/cleaning up "mixed" file descriptors / sockets.

When I create a socket using accept() and make a FILE out of it using fdopen(), what do I have to do to clean everything up? Do I need to do fclose() on the FILE, shutdown() and close() on the socket, or only the shutdown() and or close() or fclose()? If I don't do fclose(), do I have to free() the FILE pointer manually? ...

How to prevent SIGPIPEs (or handle them properly).

I have a small server program that accepts connections on a TCP or local UNIX socket, reads a simple command and, depending on the command, sends a reply. The problem is that the client may have no interest in the answer sometimes and exits early, so writing to that socket will cause a SIGPIPE and make my server crash. What's the best pr...

Data structure for assembly code? [research]

I'm planning to create a data structure optimized to hold assembly code. That way I can be totally responsible for the optimization algorithms that will be working on this structure. If I can compile while running. It will be kind of dynamic execution. Is this possible? Have any one seen something like this? Should I use structs to link...

Needless pointer-casts in C

I got a comment to my answer on this thread: http://stackoverflow.com/questions/105477 In short I had code like this: int * somefunc (void) { int * temp = (int*) malloc (sizeof (int)); temp[0] = 0; return temp; } I got this comment: Can I just say, please don't cast the return value of malloc? It is not required and ca...

Is there memset() that accepts integers larger than char?

Is there a version of memset() which sets a value that is larger than 1 byte (char)? For example, let's say we have a memset32() function, so using it we can do the following: int32_t array[10]; memset32(array, 0xDEADBEEF, sizeof(array)); This will set the value 0xDEADBEEF in all the elements of array. Currently it seems to me this ca...

How to simulate memory allocation errors

My C application uses 3rd libraries, which do their own memory management. In order to be robust, my application has code to deal with failures of library functions due to lack of free memory. I would like to test this code, and for this, I need to simulate failures due to lack of memory. What tool/s are recommended for this? My enviro...

Why isn't there a standard memswap function.

Why doesn't have the c standard a memswap function, which would probably look like: int memswap(void *ptr1, void *ptr2, size_t nbytes)? I know it'd be easy to write, but i think the libc could do some awesome tricks to speed it up like some implementations do it for memcpy. ...