c

Porting a large C project from Unix to Windows

So, I have a large C project that was built entirely on Unix (SPARC Solaris). me and several others have begun to revisit it because their was some interest in a windows build. none of us have done this with a project of such size, so for starters, has anyone ported something from unix to windows and could maybe give me some pointers or...

Declare variables at top of function or in separate scopes?

Which is preferred, method 1 or method 2? Method 1: LRESULT CALLBACK wpMainWindow(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch (msg) { case WM_PAINT: { HDC hdc; PAINTSTRUCT ps; RECT rc; GetClientRect(hwnd, &rc); hdc = BeginPa...

contradiction between c-faq and my compiler

The C-faq says that the code: int i = 7; printf("%d\n", i++ * i++); prints 49. Regardless of the order of evaluation, shouldn't it print 56? When I ran this code on my Turbo C 3.0 compiler it gave me the output of 56. Why is there a contradiction? ...

#define with parameters...why is this working?

what is going on here? #define CONSTANT_UNICODE_STRING(s) \ { sizeof( s ) - sizeof( WCHAR ), sizeof(s), s } . . . . UNICODE_STRING gInsufficientResourcesUnicode = CONSTANT_UNICODE_STRING(L"[-= Insufficient Resources =-]"); this code is working. I need to see the pre-processors expansion. and whats ...

How to batch FFT in C

I am trying to do a batch FFT on 50 images using the following snippet: pix3 = n*pix1*pix2; fftwf_complex *in2, *f2h; //input for FFT2 in2 = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * pix3); f2h = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * pix3); for (i = 0; i < pix3; i++) { in2[i][0] = ref20[i]; //ref20 is an array...

CUDA Project Structure

The template and cppIntegration examples in the CUDA SDK (version 3.1) use Externs to link function calls from the host code to the device code. However, Tom's comment at http://stackoverflow.com/questions/2090974/how-to-separate-cuda-code-into-multiple-files#comment-2024913 indicates that the usage of extern is deprecated. If this the...

Unexpected pointer randomly changes. Why would it change for? Breaks pointer arithmetic.

Hello. Maybe I'm being stupid but I can't figure out why a pointer is being changed in this function. I have included "printf" and "puts" to show the problem. The left braket pointer is changing and invalidates the pointer arithmetic I want to do for string manipulation. Another question I have - Is it dangerous to expect char pointers ...

Is there a simplistic library available (for multiple platforms) that makes it easy to write array data onto files?

e.g. one has a couple of arrays of ints or floats and a few integers to store. Is there a simplistic way to save them for later reloading without having to write a data format from scratch etc.? ...

Is it possible to increase accuracy of floating point arithemtic with gcc?

Hi, some program in C which does extensive floating point calculations get right results on a pc linux box, but wrong results on the SPE of the cell processor, but not on the PPU of the cell. I am using gcc compilers. I wonder if there is some gcc compilation option to increase rounding method or similar so I get single float precision ...

How to deallocate memory in prefix tree? (ANSI C)

I tried to deallocate memory in dict_free() function, but it doesn't work and I don't no why. Am I missing something? Can't figure out, what's wrong. Edit: If I call free() in dict_free() I expect to see that free'd pointer points to NULL, but that's not happening. Here is my code: #include <stdio.h> #include <stdlib.h> #include <stri...

Constructor for structs in C

Given: struct objStruct { int id; int value; }; typedef struct objStruct Object; Is there a shortcut to allocate and initialize the object, something like a C++ constructor? It could even be a preprocessor macro. Whatever makes the code shorter and more readable than this: Object *newObj = malloc(sizeof(Object)); // successf...

Can't call method in Python C extension

I'm working on making my first Python C extension, which defines a few functions and custom types. The strange thing is that the custom types are working, but not the regular functions. The top-level MyModule.c file looks like this: static PyMethodDef MyModule_methods[] = { {"doStuff", MyModule_doStuff, METH_VARARGS, ""}, {NUL...

What libraries/how to play wav file on Windows32 in C?

What libraries for C do I need to play a wav file on a Win32 system? And what is the code to use those libraries? ...

Which is better for local IPC, POSIX message queues (mqueues) or Unix domain (local) sockets?

Is it better to use POSIX message queues or Unix domain sockets for local IPC communication? I have worked with Unix sockets between machines (not domain) and I remember that making and breaking the connection would cause sockets to linger awhile before they finally went away. Moreover, if you wanted a "reliable" exchange you either had...

sprintf() with automatic memory allocation?

Hello! I'm searching for a sprintf()-like implementation of a function that automatically allocates required memory. So I want to say char* my_str = dynamic_sprintf( "Hello %s, this is a %.*s nice %05d string", a, b, c, d ); and my_str retrieves the adress of an allocated memory that holds the result of this sprintf(). In another fo...

C get mode from list of integers

I need to write a program to find the mode. Or the most occurrence of an integer or integers. So, 1,2,3,4,1,10,4,23,12,4,1 would have mode of 1 and 4. I'm not really sure what kind of algorithm i should use. I'm having a hard time trying to think of something that would work. I was thinking of a frequency table of some sort maybe whe...

Artifically Limit C/C++ Memory Usage

Is there any way to easily limit a C/C++ application to a specified amount of memory (30 mb or so)? Eg: if my application tries to complete load a 50mb file into memory it will die/print a message and quit/etc. Admittedly I can just constantly check the memory usage for the application, but it would be a bit easier if it would just die...

Trouble sending signal to child process in C

I've been trying to figure out if this is possible the way I've done it or not. This program should fork a child process that loops printing to STDOUT, and the parent should exit to return the terminal prompt. The child should then be waiting for SIGINT to tell it when to close down. However I remember reading that SIGINT is only send...

How to consume java webservice in C

My project has a requirement where I have to develop a C component which consumes java web service. This C module has to be integrated again with Unsion (which has unify as the language). I am new to both of these things and not sure where to start. Can someone help me by pointing to some libraries or anything which helps in calling jav...

How to find the min and max of a set of numbers in C without loops?

Lets say I have 10 numbers (doubles) and I have to find the smallest number and the biggest number without using loops, how would I do so? ...