c

Memory Bandwidth Usage

How do you calculate memory(RAM) bandwidth used? Which performance counters are required? I came across a tool that was able to do it, the "Rightmark multi-threaded memory test". But unlike the rest of Rightmark's tests, I haven't found the source code for it, just the binaries. Thanks in Advance Tom De Bie ...

How to embed a flash player in a GTK app?

Hi, has anyone tried to embed a Adobes FlashPlayer into a c-written Gtk-Application? Is it possible? Are there any good points to start? P.S.: I do not want to embed the WebKit or Gecko renderengine into my application! ...

GetOpenFileName() does not refresh when changing filter

I use GetOpenFilename() to let the user select a file. Here is the code: wchar_t buffer[MAX_PATH] = { 0 }; OPENFILENAMEW open_filename = { sizeof (OPENFILENAMEW) }; open_filename.hwndOwner = handle_; open_filename.lpstrFilter = L"Video Files\0*.avi;*.mpg;*.wmv;*.asf\0" L"All Files\0*.*\0"; ope...

Consistent pseudo-random numbers across platforms

Hello, I am looking for a way to generate pseudo random number sequences that will yield identical sequence results for a given seed across any platform. I am assuming that rand()/srand() is not going to be consistent (I could easily be wrong about this assumption). ...

Use of clock_getres - newbie Linux C

I'm trying to determine the granularity of the timers on my Linux box. According to the man pages for clock_getres, I should be able to use this snippet: #include <time.h> #include <stdio.h> int main( int argc, char** argv ) { clockid_t types[] = { CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID, (...

Is it still worth trying to create optimizations for sqrt() in C?

Are the old tricks (lookup table, approx functions) for creating faster implementations of sqrt() still useful, or is the default implementation as fast as it is going to get with modern compilers and hardware? ...

Lightweight and portable regex library for C/C++?

Hello, What is a good and portable regex library for C/C++? (C++ preferably) ...

Win32: Modal dialog not returning focus

Hi, I'm writing a win32 wrapper classes, mainly to learn more about win32 programming. To get around the problem of c-style callbacks, the following method stores/retrieves the pointer using SetWindowLong/GetWindowLong and passes it to the actual winproc. LRESULT CALLBACK WinClass::WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM l...

What's the use of do while(0) when we define a macro?

I'm reading the linux kernel and I found many macros like this: #define INIT_LIST_HEAD(ptr) do { \ (ptr)->next = (ptr); (ptr)->prev = (ptr); \ } while (0) Why do they use this rather than define it simply in a {}? ...

Problem replacing Linux system calls using LD_PRELOAD

I am trying to write a program that allows a binary to be run, substituting a certain file when requested with another. It is a library with simple replacements for the system call functions, that is used with LD_PRELOAD. The problem is that it catches opens for reading (the substitute file is read instead), but writes always go back to ...

Why do I get connection refused after 1024 connections?

I am testing on a local Linux server with both the server and client in the same server. After about 1024 connections, in my code, where I connect, I get connection refused. At first I thought it was the fd_set_max limit of 1024 for select and changed the server to do poll instead of select and I still don't get past this number. My ulim...

How to read output and give input to a program from c program?

This is with reference to the below question http://stackoverflow.com/questions/70842/execute-program-from-within-a-c-program How do I do the same on windows with Tiny C Compiler? I need to execute a .exe fro c program and give input to it from within the same C program by using a file or string as source and read the output from it into...

Can the C main() function be static?

Can the main() function be declared static in a C program? If so then what is the use of it? Is it possible if I use assembly code and call the static main() function myself (consider embedded programs)? ...

Portability of open(...O_DIRECT) in C?

In C file I/O, the O_DIRECT flag can be used to minimize cache effects for a file being open()ed. I understand that this is not a POSIX feature, has been present in the Linux kernel since version 2.4.10, and that Linus is opposed to the interface in general. Under NetBSD, it seems to work as advertised. Example call: int fd = open(f...

Parse a String in C

Using just C I would like to parse a string and a) count the occurrences of a character in a string (so i.e. count all the e's in a passed in string) b) Once counted (or even as I am counting) replace the e's with 3's Thanks. ...

Why was Matlab written in C instead of Fortran?

As you may know, Fortran is a language for scientific computing. however, the kernel of the most famous high level language for scientific computing has been written in C instead of Fortran. Why? ...

Convolution Filter - Float Precision C Vs Java

Hey! I'm porting a library of image manipulation routines into C from Java and I'm getting some very small differences when I compare the results. Is it reasonable that these differences are in the different languages' handling of float values or do I still have work to do! The routine is Convolution with a 3 x 3 kernel, it's operated ...

Change type of ViewData in extended controller

I created my own CustomController base class that inherits from Controller. Likewise I created my own CustomViewData that inherits from ViewDataDictionary. The CustomController class has a ctor that accepts a CustomViewData as parameter. All my controllers inherit from CustomController and pass in their inherited CustomViewData. Now I w...

Resources for learning C program design

Coming from a OO background (C#/java) I'm looking for resources to learn how to design pure C programs well. Whilst i'm familiar with the syntax of C, and i can write small programs, i'm unsure of the approach to take for larger applications, and what techniques to employ. Anything you guys can recommend. EDIT: I'm happy to completly...

call different child function from same parent function

Im looking to have a common parent function like so void main (param 1, param 2) { <stuff to do> param1(); print("The function %s was called", param 2); <more stuff to do> } Where param 1 will be the name of the function to be called and param 2 will be some descriptive text. param 2 is easy and I have that solved, bu...