c

Int in a simulated memory array of uchar

In C, in an Unix environment (Plan9), I have got an array as memory. uchar mem[32*1024]; I need that array to contain different fields, such as an int (integer) to indicate the size of memory free and avaliable. So, I've tried this: uchar* memp=mem; *memp=(int)250; //An example of size I want to assign. I know the size of an int i...

Calling a C++ Shared Lib within a C program...how to manage?

hi all, i'd like to write a wrapper for a C++ framework. this framework is kinda buggy and not really nice and in C++. so i'd like to be able to call their methods from outside (via good old C file) of their framework by using just one shared lib. this sounds like the need for a wrapper that encapsulates the wanted framework methods fo...

How to ignore hidden files with opendir and readdir in C library

Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur = readdir(pd)) puts(cur->d_name); What I get is kind of messy: including dot (.), dot-dot (..) and file names that end with ~. I want to do exactly the same thing as the command ls. How do I fix this, please? ...

Memory Based Data Server for local IPC

I am going to be running an app(s) that require about 200MB of market data each time it runs. This is trivial amount of data to store in memory these days, so for speed thats what i want to do. Over the course of a days session I will probably run, re-run, re-write and re-run etc etc one or more applications over and over. SO, the ques...

How to write a vb.net code to compile and execute C programs?

I'm trying to make a vb.net application that has got 2 textboxes, 2 radio buttons and 2 buttons(one named compile and the other 'run'). How can I load the content of a C/C++ file into the 1st textbox and on clicking the compile button, i should be able to show the errors or the C/C++ program in the 2nd textbox. On clicking Run, I should ...

How to check if the binary representation of an integer is a palindrome?

How to check if the binary representation of an integer is a palindrome? ...

Git ignore file for C projects

I've just started to learn C (using Thinking In C) and I'm wondering about what files I should be ignoring in a C project's git repository. No suggestion can be too obvious -- I'm a total noob. Thanks! ...

Semicolon at the ends of if-statements and functions in C

I just ran into some code that overuse semicolons, or use semicolon for different purposes that I am not aware of. I found semicolons at the end of if-statements and at the end of functions. For instance: int main (int argc, char * argv[]) { // some code if (x == NULL) { // some code }; <----- ...

Code reuse in exception handling

I'm developing a C api for some functionality written in C++ and I want to make sure that no exceptions are propagated out of any of the exported C functions. The simple way to do it is making sure each exported function is contained in a: try { // Do the actual code } catch (...) { return ERROR_UNHANDLED_EXCEPTION; } Let's say...

Compile a DLL in C/C++, then call it from another program

I want to make a simple, simple DLL which exports one or two functions, then try to call it from another program... Everywhere I've looked so far, is for complicated matters, different ways of linking things together, weird problems that I haven't even begun to realize exist yet... I just want to get started, by doing something like so: ...

Too many calls to mprotect

I am working on a parallel app (C, pthread). I traced the system calls because at some point I have bad parallel performances. My traces shown that my program calls mprotect() many many times ... enough to significantly slow down my program. I do allocate a lot of memory (with malloc()) but there is only a reasonable number of calls to ...

Connection refused after some time on threaded process in tcp socket requests (c/linux)

I'm trying to make process that takes number of requests each second, on each request new thread is created. Each thread then opens socket connection to address (http port) sends HEAD requests, gets response and closes socket. Problem I'm having comes when i put more then 3 requests per second, after some time i get error in send() part...

Dynamic array of structs and function call f(const struct_type *const data[])

The following code warns about incompatible type. What is the proper way to solve this code? thanks typedef struct a_struct struct_type; void f(const struct_type *const data[], unsigned n); void test(unsigned n) { struct_type **v; assert(n); v = malloc(n * sizeof(struct_type *)); /* fill v with new struct_type (with a ma...

How to write a vb.net code to compile C/C++ programs?

I'm trying to make a vb.net application that has got 2 textboxes, 7 radio buttons and 2 buttons(one named compile and the other 'run'). How can I load the content of a C/C++(or any programming language) file into the 1st textbox and on clicking the compile button, i should be able to show the errors or the C/C++ program in the 2nd textbo...

Is there any performance difference between for() and while()?

Or is it all about semantics? ...

Why is 2[myArray] valid C syntax?

Duplicate In C arrays why is this true? a[5] == 5[a] Given an array myArray[5] = { 0, 1, 2, 3, 4 }; an element can be accessed as 2[myArray] Why? When I see this expression I'm imagining C trying to access the pointer "2" and failing to add "myArray" pointer increments to dereference that address. What am I missing? ...

Handling more than 1024 file descriptors, in C on Linux

I am working on a threaded network server using epoll (edge triggered) and threads and I'm using httperf to benchmark my server. So far, it's performing really well or almost exactly at the rate the requests are being sent. Until the 1024 barrier, where everything slows down to around 30 requests/second. Running on Ubuntu 9.04 64-bit. ...

Is there a tool to convert ANSI C code to C#?

I need to import some ANSI C code into a project I'm working on. For reasons I prefer not to go into, I want to refactor the code to C# rather than trying to wrap the original code. It will take me perhaps a couple of days to do the work by hand, but before I start, is there an automated tool that can get me most of the way there? I'm a ...

What is the best path for working with 3d graphics?

Right now, I think a combination of C and openGL is what I need to learn, but it seems like there is still more to it that I need. Also, I'm not sure where to start. I know some C, from reading the C Programming Language (K&R). ...

What files could have been included?

I would like to be able to get a list of all possible files included in a C source file. I understand there are complications with other # directives (for instance, an #ifdef could either prevent an include or cause an extra include). All I'm looking for is a list of files that may have been included. Is there a tool that already do...