c

C Preprocessors - for homework

I am not understanding this question...can you tell me what to do in a short message...or give me some links to search....please, it's urgent You are required to implement a C preprocessor. The Preprocessor is to be implemented as a command-line tool, the input to which is a C source file (.c extension) and the output is the preprocesse...

Handling fpu exception on windows

I would like to handle fpu exception on windows, something like: #include <math.h> #include <fenv.h> #include <stdio.h> int main() { double b = 0; int raised; feclearexcept (FE_ALL_EXCEPT); b /= 0; raised = fetestexcept (FE_OVERFLOW | FE_INVALID); if (raised & FE_OVERFLOW) { printf("over\n");} if (raised & F...

Drain the instruction pipeline of Intel Core 2 Duo?

I'm writing some micro-benchmarking code for some very short operations in C. For example, one thing I'm measuring is how many cycles are needed to call an empty function depending on the number of arguments passed. Currently, I'm timing using an RDTSC instruction before and after each operation to get the CPU's cycle count. However, I...

fcntl, lockf, which is better to use for file locking?

Looking for information regarding the advantages and disadvantages of both fcntl and lockf for file locking. For example which is better to use for portability? I am currently coding a linux daemon and wondering which is better suited to use for enforcing mutual exclusion. ...

Using pipes in C for parent-child IPC makes program block

I am writing a server which fork()'s off a child process when it accepts a socket connection. As the child communicates with a client, it must send some of that information back to the parent. I am using a pipe to accomplish this. The problem is that when I try to do the parent-child IPC, the parent blocks when reading input from the c...

Which C Compiler do you recommend for windows

Which C Compiler do you recommend for Windows (Not C++, C ANSI) Related: c compiler for windows C/C++ Compiler for windows ...

Is there an auto-resizing array/dynamic array implementation for C that comes with glibc?

Is there a dynamic array implementation in glibc or any of the standard Linux libraries for C? I want to be able to add to a list without worrying about its size. I know std::vector exists for C++, but I need the C equivalent. ...

How am I incorrectly using the round() function in C?

I'm getting unexpected results from the round() and roundf() functions in the math.h library. Here is the sample code: #include <stdio.h> #include <math.h> int main(void) { float f; double d; /* Note man page says that roundf() returns a float and round() returns a double */ f = roundf(1.2); d = round(1.2);...

how to print a string vertically in c?

Ok the output is supposed to look like this: ./a 3 4 8 2 3 4 8 2 This is what I have so far, but I am lost and can only get the first integer to print (we have to use GetInt, which gets the specified integer in the string): int main (int argc, char*argv []){ int v; int i; i = 1; v = GetInt(argc, argv...

Which is better code for converting BSTR parameters to ANSI in C/C++?

So far I've discovered I can convert incoming BSTRs to ANSI in two (of many?) ways, and I'm curious to know whether one is "better" than the other with respect to speed / efficiency etc. The way I've been using for a while is use the USES_CONVERSION and W2A macros, e.g. BSTR __stdcall F(BSTR p1, BSTR p2 ) { USES_CONVERSION; LP...

calling c dll from fortran

yes, I need to do the following on visual fortran... any good resources ? ...

Have you dealt with space hardening?

I am very eager to study best practices when it comes to space hardening. For instance, I've read (though I can't find the article any longer) that some core parts of the Mars rovers did not use dynamic memory allocation, in fact it was forbidden. I've also read that old fashioned core memory may be preferable in space. I was looking a...

Difference between K&R and ANSI function outputs

I ran the following code, and found some strange output. int mean_ansi (int num1, int num2) { printf ("In %s\n", __FUNCTION__); printf ("num1,num2 is %d,%d\n", num1, num2); return (num1 + num2) / 2; } int mean_K_and_R (num1, num2) int num1, num2; { printf ("In %s\n", __FUNCTION__); printf ("num1,num2 is %d,%d\n", num1,...

mpeg 2 decoding

I want to understand how video and audio decoding works, specially the timing synchronization (how to get 30fps video, how to couple that with audio, etc.). I don't want to know ALL the details, just the essence of it. I want to be able to write a high level simplification of an actual video/audio decoder. Could you provide pointers to ...

C : pthread dataspecific destructor called only once

From pthread_key_create manpage : An optional destructor function may be associated with each key value. At thread exit, if a key value has a non-NULL destructor pointer, and the thread has a non-NULL value associated with the key, the function pointed to is called with the current associated value as its sole argume...

When is assembler faster than C?

One of the stated reasons for knowing assembler is that, on occasion, it can be employed to write code that will be more performant than writing that code in a higher-level language, C in particular. However, I've also heard it stated many times that although that's not entirely false, the cases where assembler can actually be used to g...

How can I index a lot of txt files? (Java/C/C++)

I need to index a lot of text. The search results must give me the name of the files containing the query and all of the positions where the query matched in each file - so, I don't have to load the whole file to find the matching portion. What libraries can you recommend for doing this? update: Lucene has been suggested. Can you give m...

How to obtain the correct physical size of the monitor?

How can I get the size of the display in centimeters or inches? This code does not always works correctly: HDC hdc = CreateDC(_T("DISPLAY"),dd.DeviceName,NULL,NULL); int width = GetDeviceCaps(hdc, HORZSIZE); int height = GetDeviceCaps(hdc, VERTSIZE); ReleaseDC(0, hdc) Especially for multi-monitor configuration. Update: I need to get...

CRC Calculation

I'm trying to interface with a 3rd party system and they have provided a code sample to calculate a CRC value when sending text data. The C code the vendor provided looks like this: #define CRCRES 0xf0b8 /* residue for good verify */ #define DEBUG unsigned crctbl[] = {0x0000, 0x1081, 0x2102, 0x3183, 0x4204, 0...

Uses of SO_REUSEADDR ?

I have used SO_REUSEADDR to have my server which got terminated to restart with out complaining that the socket is already is in use. I was wondering if there are other uses of SO_REUSEADDR? Have anyone used the socket option for other than the said purpose? ...