c

Standard interface for the C language for generating syslog messages

Which way is standard to generate IETF-syslog messages in the C language? There is the header <syslog.h>. But it provide no options to use the STRUCTURED-DATA mechanism (rfc-5424). Of course, messages could be constructed by hand directly to a socket. But it seems that such way is not standard. Is there another standard way? ...

Using VBO's and CPU usage is very high

I'm really not sure what to do anymore. I'v made my application use VBO's and my cpu usage still goes into the 70's and 80's. My render proceedure works like this: Set the camera transformation if the shape has not been tesselated, tesselate it. create it's VBO if it has a VBO, use it. You will notice I have display lists too, I might ...

Windows.h in C using Turbo-C

Hi, I cannot find windows.h in my include folder of Turbo C and hence cannot work with the Win32 api's Can someone please suggest a workaround? thanks ...

In game programming, what are the specific C++ or STL features that causes performance hogs ?

My question is mostly about STL than the rest of the C++ that can be compared (I guess) to be as much fast as C a long as classes aren't used at every corner. STL is standard for games and in engines like OGRE3D, but I was wondering that if STL's features are nice to use, the problem is while I don't really know how they work, I should ...

Algorithm to pick values from array that sum closest to a target value?

I have an array of nearly sorted values 28 elements long. I need to find the set of values that sums to a target value provided to the algorithm (or if exact sum cannot be found, the closest sum Below the target value). I currently have a simple algorithm that does the job but it doesn't always find the best match. It works under idea...

How can I keep the kernel from sending RST packets from raw sockets on mac os x?

I am using raw sockets with TCP. Whenever a packet gets sent to me, my computer send a RST packet back. I tried http://udi.posterous.com/suppressing-tcp-rst-on-raw-sockets, which isn't working: int main(void) { struct addrinfo *info, hints, *p; int status, sock; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; h...

What are good test cases for benchmarking & stress testing substring search algorithms?

I'm trying to evaluate different substring search (ala strstr) algorithms and implementations and looking for some well-crafted needle and haystack strings that will catch worst-case performance and possible corner-case bugs. I suppose I could work them out myself but I figure someone has to have a good collection of test cases sitting a...

#define or enum?

When programming in C, is it better practice to use #define statements or enums for states in a state machine? ...

How can you be DRY with a programming language that doesn't have Reflection?

Any programming language that does not have a suitable reflection mechanism I find seriously debilitating for rapidly changing problems. It seems with certain languages its incredible hard or not possible to do: Convention over Configuration Automatic Databinding AOP / Meta programming with out reflection. Some example languages th...

Linux / C / GTK+ Set GtkTextView background to the default window colour

I want to set the GtkTexetView background colour to the window's default colour so that it looks like a GtkLabel. Take a look at these images, but please note that I want it for C and not PHP, and I use GNOME, not MS Windows. ...

Which is faster — sorting or multiplying a small array of elements?

Reading through Cactus Kev's Poker Hand Evaluator, I noticed the following statements: At first, I thought that I could always simply sort the hand first before passing it to the evaluator; but sorting takes time, and I didn't want to waste any CPU cycles sorting hands. I needed a method that didn't care what order the five cards were g...

epoll: Distinguishing "listener" FDs

How can I distinguish between "listener" file descriptors and "client" file descriptors? Here's what I saw in the manpage example: if(events[n].data.fd == listener) { ... } else { ... } 'But what if I don't have access to listener? Sorry if this is a vague question. I'm not quite sure how to word it. ...

libxml2 error with namespaces and xpath

hello, I am pasting some code here that compiles with no warning using gcc file.c -lxml2, assuming that libxml2 is installed in your system. #include libxml/parser.h> #include libxml/xpath.h> #include assert.h> #include libxml/tree.h> #include libxml/xpathInternals.h> xmlDocPtr getdoc (char *docname) { xmlDocPtr doc; doc = x...

Linker errors only when I make a function call to a recently added header file

So, I recently added a header file (and corresponding source file) to a project, along with a header file that file required, and an object file that the file required. Everything compiles fine, unless I actually make a call to one of the functions declared in the newly added header file. This is all using Visual Studio Express 2008. ...

Call C/C++ code form a fortran program in visual studio? (How to compile mixed C and fortran code in visual studio)

Hi every one, i am looking for a way, how i can integrate a c++ code with fortran code (i want simply call some C/C++ functions in the fortran code). I have found some proposals for gcc or console compilers, but i have not any idea how to translate this approach to solve integrationproblem within the visual studio. At the time I am thi...

Why does MapViewOfFile return an unusable pointer for rapidxml?

As suggested: I have a file which is larger than 2 giga. I am mapping to memory using the following function: char* ptr = (char*) MapViewOfFile( map_handle, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0, 0 ); I parse ptr to rapidxml which accepts Ch* . As per the documentation from rapidxml ptr should be modifiable but since it is decl...

Web technologies for an embedded server

Hey everyone, I've recently started a new web development project for an embedded device and wanted to solicit some recommendations for technologies to use. The device will serve HTML pages which include AJAX code to retrieve data from a JSON server. We're tentatively using Cherokee as the web server, though we're not tied to it. Curre...

Variable Multiplication in C?

//Hydroelectric Dam Helper #include <stdio.h> #define GRAV 9.80 #define EFINC 0.9 #define EFINC2 90 int main() { //Defines all the variables to be used double height, work, mass; printf("Height of dam (in meters):"); scanf("%lf", &height); printf("Flow of water (in thousand cubic meters per second):"); scanf("%lf", &mass); ...

including <stdlib.h> causes segmentation fault

I am writing a program to read info from a text file and I had everything working. The problem is that I am trying to add the functionality to calculate the mean of some of fields and have to convert the strings to doubles. I noticed that atof would work in some cases but would return -1 for the most part. i then realized that I didn'...

SegFault after scanf?

#include <stdio.h> #define TimeConverter 60 #define TempFormula time * time * 4 / time + 2 - 20 double HoursMinToTime(int hour, int min); double Temperature(double time); int main() { int hour, min; double time, temperature; printf("Hours and minutes: "); scanf("%d %d", hour, min); //Segfault HERE time = HoursM...